博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.Solr构建索引-查询索引
阅读量:7045 次
发布时间:2019-06-28

本文共 5373 字,大约阅读时间需要 17 分钟。

折腾了一上午终于完整的展示了一下Solr功能
现在总结如下
0.注意事项
 <1.在schema.xml里需要创建一个  fieldType name="text_en" 设置它的分词器等参数
 <2.在schema.xml里需要创建几个fields<最好与源数据字段对应>,field name="name"     type="text_en" 设置它所属的fieldtype
1.配置schema.xml文件
<?xml version="1.0" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at
    
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<schema name="example core one" version="1.1">
  <types>
      <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
      <fieldType name="text_en" class="solr.TextField" positionIncrementGap="100">
          <analyzer type="index">
              <tokenizer class="solr.StandardTokenizerFactory"/>
              <!-- in this example, we will only use synonyms at query time
        <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
        -->
              <!-- Case insensitive stop word removal.
          add enablePositionIncrements=true in both the index and query
          analyzers to leave a 'gap' for more accurate phrase queries.
        -->
              <filter class="solr.StopFilterFactory"
                      ignoreCase="true"
                      words="stopwords_en.txt"
                      enablePositionIncrements="true"
                />
              <filter class="solr.LowerCaseFilterFactory"/>
              <filter class="solr.EnglishPossessiveFilterFactory"/>
              <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
              <!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory:
        <filter class="solr.EnglishMinimalStemFilterFactory"/>
 -->
              <filter class="solr.PorterStemFilterFactory"/>
          </analyzer>
          <analyzer type="query">
              <tokenizer class="solr.StandardTokenizerFactory"/>
              <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
              <filter class="solr.StopFilterFactory"
                      ignoreCase="true"
                      words="stopwords_en.txt"
                      enablePositionIncrements="true"
                />
              <filter class="solr.LowerCaseFilterFactory"/>
              <filter class="solr.EnglishPossessiveFilterFactory"/>
              <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
              <!-- Optionally you may want to use this less aggressive stemmer instead of PorterStemFilterFactory:
        <filter class="solr.EnglishMinimalStemFilterFactory"/>
 -->
              <filter class="solr.PorterStemFilterFactory"/>
          </analyzer>
      </fieldType>
  </types>
   
 <fields>  
  <!-- general -->
  <field name="id"       type="text_en"    indexed="true"  stored="true"  multiValued="false" required="true"/>
  <field name="name"     type="text_en"    indexed="true"  stored="true"  multiValued="false" />
 </fields>
 <!-- field to use to determine and enforce document uniqueness. -->
 <uniqueKey>id</uniqueKey>
 <!-- field for the QueryParser to use when an explicit fieldname is absent -->
 <defaultSearchField>name</defaultSearchField>
 <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
 <solrQueryParser defaultOperator="OR"/>
</schema>
2.配置solrconfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at
    
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<!--
 This is a stripped down config file used for a simple example... 
 It is *not* a good example to work from.
-->
<config>
  <luceneMatchVersion>LUCENE_36</luceneMatchVersion>
  <!--  The DirectoryFactory to use for indexes.
        solr.StandardDirectoryFactory, the default, is filesystem based.
        solr.RAMDirectoryFactory is memory based, not persistent, and doesn't work with replication. -->
  <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}"/>
  <updateHandler class="solr.DirectUpdateHandler2" />
  <requestDispatcher handleSelect="true" >
    <requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" />
  </requestDispatcher>
 
  <requestHandler name="standard" class="solr.StandardRequestHandler" default="true" />
  <requestHandler name="/update" class="solr.XmlUpdateRequestHandler" />
  <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />
    <requestHandler name="/select" class="solr.SearchHandler" />    
      
  <!-- config for the admin interface -->
  <admin>
    <defaultQuery>solr</defaultQuery>
  </admin>
</config>
3.导入数据测试
    <1.将post.jar放入源数据文件夹
    <2.
图片加载测试数据
4.测试查询:
   输入查询关键字 ipod
  返回结果(说明OK)
 
图片
5.更详细的内容将在后面的研究中补充起来

转载于:https://www.cnblogs.com/bobsoft/archive/2012/10/07/2714521.html

你可能感兴趣的文章
centos 查看每天应用程序的iowait
查看>>
.Net Micro Framework研究—中文显示
查看>>
修改虚拟机MAC地址的方法
查看>>
WINDOWS7更改访问windows共享的用户名和密码
查看>>
Mac下好用的批量文件扩展名修改工具
查看>>
配置gitlab环境实现代码管理及Web Hook测试和ldap认证
查看>>
几副工作对联@Alibaba
查看>>
五步教你使用JCS快速搭建缓存环境
查看>>
XenApp_XenDesktop_7.6实战篇之四:AD、DNS服务器高级配置
查看>>
利用IPSec使用策略和规则提升网络安全性
查看>>
虚拟资源引流变现
查看>>
015 有趣的查询条件
查看>>
Delphi下使用指针的简单总结
查看>>
iBatis2配置
查看>>
摩卡端到端监控管理(Mocha E2E)解决方案
查看>>
YUM安装LNMP架构
查看>>
ISA Server 2006 安全保障指南
查看>>
iOS APP提交上架最新流程(转)
查看>>
电力基本知识
查看>>
git合并历史提交
查看>>