zoukankan      html  css  js  c++  java
  • .Solr构建索引查询索引

    折腾了一上午终于完整的展示了一下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.图片加载测试数据
       输入查询关键字 ipod
      返回结果(说明OK)
      图片
    5.更详细的内容将在后面的研究中补充起来
  • 相关阅读:
    CentOS6.4 安装OpenResty和Redis 并在Nginx中利用lua简单读取Redis数据
    nginx缓存批量清除
    Centos下Yum安装PHP5.5,5.6
    php中的脚本加速扩展opcache
    Centos 6.5 挂载硬盘 4K对齐 (笔记 实测)
    centos6.5下编译安装FFmpeg
    Python学习九:列表生成式
    Python Select 解析
    Python之基于socket和select模块实现IO多路复用
    Python之路,Day9 , IO多路复用(番外篇)
  • 原文地址:https://www.cnblogs.com/bobsoft/p/2714521.html
Copyright © 2011-2022 走看看