来自多个字段的solr自动完成关键字

时间:2012-11-01 00:15:46

标签: solr autocomplete

我是Solr的新手,希望根据两个字段标题和说明实现自动完成功能。此外,结果集应进一步受到其他字段的限制,例如id和category。样本数据:

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.

所需的自动填充结果:

brown fox
brown leaves
brown color

以下是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"/>

查询请求:

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

2 个答案:

答案 0 :(得分:4)

使用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"/>

查询请求:

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

结果:

brown color
brown fox
brown leaves

希望这有助于某人

答案 1 :(得分:0)

如何制作字段spellcheck_text并使用复制字段功能,以便titledescription自动发往spellcheck_text

  

...指示Solr您希望它复制它在中看到的任何数据   添加到索引的文档的“源”字段,在“dest”中   该文件的领域。 ... 原始文本是从。发送的   在任何已配置的分析器之前,“source”字段到“dest”字段   调用origin或destination字段。

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