.Solr构建索引-查询索引

2019-03-27 01:13|来源: 网路

折腾了一上午终于完整的展示了一下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.更详细的内容将在后面的研究中补充起来

转自:http://www.cnblogs.com/bobsoft/archive/2012/10/07/2714521

相关问答

更多
  • 在solr与tomcat整合文章中,我用的索引库是mycore,现在就以这个为例。 首先要准备jar包:solr-dataimporthandler-4.8.1.jar、solr-dataimporthandler-extras-4.8.1.jar和mysql-connector-java-5.0.7-bin.jar这三个包到solr的tomcat的webapps\solr\WEB-INF\lib下 在这个文件夹的conf下配置两个文件,添加一个文件。先配置solrconfig.xml。 在该文件下添加一个 ...
  • 如果要查找索引的物理磁盘大小,可以按照solrconfig.xml中的定义查看“dataDir”下的“data / index”文件夹。 例如。 在示例索引中,它是example / solr / data / index文件夹。 如果您正在查找文档的数量,那么您可以查看stats.jsp页面或搜索“ : ”。 如果您正在寻找了解内存使用情况,可以从stats.jsp开始 - 并查看文档计数,各种字段缓存大小等。 我担心你需要做更多的研究来了解你的记忆要求,描述应用程序和计划容量。 If you are l ...
  • 如果您还没有向Solr提供Haystack为您生成的schema.xml文件,您也会收到此错误,如文档中所述。 http://docs.haystacksearch.org/dev/tutorial.html#reindex The schema.xml was malformed as I had copied additional text from the console.
  • 您正在看到此行为,因为您要做的第一件事就是清除索引。 solr.Delete(SolrQuery.All) 这将从索引中删除所有文档。 因此,一旦重建索引开始,索引将为空。 现在,在后续代码中,您将批量添加回索引。 但是,在发出提交之前,查询索引的用户将看不到您添加到索引的任何新文档。 由于您正在批量添加文档和发布提交,因此解释了在重建时文档数量增加的原因以及为什么所有文档都不可见。 在最后一次提交发布之前,索引中的计数和总文档数不会是7500。 可能有几个选项可以帮助您缓解这种情况。 使用commitW ...
  • 使用Indexing_Performance和ImproveIndexingSpeed查看SolrPerformanceFactors Check out SolrPerformanceFactors with Indexing_Performance and ImproveIndexingSpeed
  • DIH提供执行Delta导入的功能 。 DIH将保留上次成功构建的时间戳。 因此,如果您的数据库正在维护更新记录的时间戳,则delta查询将考虑在最后一个构建时间戳之后更新的所有记录。 它是为指数增量建立的一种方式。 DIH provides the ability to perform Delta imports. DIH will maintain the timestamp for the last successful builds. SO if your database is maintaini ...
  • Solr不会将文件存储在最后,因此没有从solr获取原始PDF文件的范围。 但是您可以存储文件的路径,并可以在用户界面中提供要下载文件的链接。 您可以使用solr给出的路径并从该位置获取文件。 Solr won't store the files at its end, So there is no scope of getting the original PDF file from solr. But you can store the path of the file and can provide ...
  • 我想你想刷新索引的原因是因为你想要近实时搜索。 实质上,您希望搜索即时反映添加的文档。 在solr中,通常由softCommits或hardCommit通过openSearcher = true进行控制。 在这里阅读更多 https://lucidworks.com/2013/08/23/understanding-transaction-logs-softcommit-and-commit-in-sorlcloud/ 要点是这个 硬承诺是关于耐久性,软承诺是关于可见性 现在,如果我明白你所做的这一切都是为 ...
  • 您需要考虑对搜索查询有意义的内容,但有一些规则。 第一个要求是唯一键需要具有相同的名称,并且在集合中是唯一的,否则Solr无法整理结果。 如果您希望获得某种合理的结果排名,则需要一些常见的字段 。 例如,我有两个集合:一个是产品数据,另一个是包含产品相关文档。 我有一个唯一的密钥: id和我有共同的标题和内容字段 ,当我想要查询两个集合时。 我还有一个高级搜索界面,我可以在其中查询产品ID等特定字段。 “统一核心”是跨两个或多个核心处理搜索的典型方式,请参阅此Stack Overflow答案,了解如何设置 ...