简体   繁体   English

Solr自动完成关键字来自多个领域

[英]solr autocomplete keywords from multiple fields

I'm new to Solr and would like to implement an autocomplete feature based on two fields title and description. 我是Solr的新手,并且希望基于标题和描述这两个字段实现自动完成功能。 In addition the resultset should be further restricted by other fields such as id and category. 此外,结果集应进一步受其他字段(例如ID和类别)限制。 Sample data: 样本数据:

Title: The brown fox lives in the woods
Description: The fox is found in the woods where brown leaves cover the ground. The animal's fur is brown in color and has a long tail.

Desired autocomplete result: 所需的自动完成结果:

brown fox
brown leaves
brown color

Here are the relevant entries from schema.xml: 以下是schema.xml中的相关条目:

<fieldType name="autocomplete" class="solr.TextField" positionIncrementGap="100">
 <analyzer type="index">
   <tokenizer class="solr.WhitespaceTokenizerFactory"/>
   <filter class="solr.LowerCaseFilterFactory"/>
   <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="25" />
 </analyzer>
 <analyzer type="query">
   <tokenizer class="solr.WhitespaceTokenizerFactory"/>
   <filter class="solr.LowerCaseFilterFactory"/>
 </analyzer>
</fieldType>


<field name="id" type="int" indexed="true" stored="true"/>
<field name="category" type="string" indexed="true" stored="true"/>
<field name="title" type="text_general" indexed="true" stored="true"/>
<field name="description" type="text_general" indexed="true" stored="true"/>

<field name="ac-terms" type="autocomplete" indexed="true" stored="false" multiValued="true" omitNorms="true" omitTermFreqAndPositions="false" />
<copyField source="title" dest="ac-terms"/> 
<copyField source="description" dest="ac-terms"/>

Query request: 查询请求:

http://localhost:9090/solr/select?q=(ac-terms:brown)

Solved using ShingleFilterFactory with the following configuration: 使用ShingleFilterFactory通过以下配置解决:

<fieldType name="autocomplete" class="solr.TextField" positionIncrementGap="100">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
    <filter class="solr.ShingleFilterFactory" maxShingleSize="2" outputUnigrams="false"/>
    <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  </analyzer>
</fieldType>

<field name="ac-terms" type="autocomplete" indexed="true" stored="false" multiValued="true" omitNorms="true" omitTermFreqAndPositions="false" />
<copyField source="title" dest="ac-terms"/>
<copyField source="description" dest="ac-terms"/>

Query request: 查询请求:

http://localhost:9090/solr/select?q=&facet=true&facet.field=ac-terms&facet.prefix=brown 

Result: 结果:

brown color
brown fox
brown leaves

Hope this helps someone 希望这可以帮助某人

What about making a field spellcheck_text and using the copy field feature so that the title and description are automatically destined to spellcheck_text ? 如何制作一个字段spellcheck_text并使用复制字段功能,以便将titledescription自动指定到spellcheck_text呢?

...instruct Solr that you want it to duplicate any data it sees in the "source" field of documents that are added to the index, in the "dest" field of that document. ...指示Solr您希望它复制添加到索引的文档的“目标”字段中该文档的“源”字段中看到的所有数据。 ... The original text is sent from the "source" field to the "dest" field, before any configured analyzers for the originating or destination field are invoked. ...在调用任何为原始或目标字段配置的分析器之前, 原始文本将从“源”字段发送到“目标”字段。

http://wiki.apache.org/solr/SchemaXml#Copy_Fields http://wiki.apache.org/solr/SchemaXml#Copy_Fields

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM