[英]solr autocomplete keywords from multiple fields
我是Solr的新手,並且希望基於標題和描述這兩個字段實現自動完成功能。 此外,結果集應進一步受其他字段(例如ID和類別)限制。 樣本數據:
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)
使用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
希望這可以幫助某人
如何制作一個字段spellcheck_text
並使用復制字段功能,以便將title
和description
自動指定到spellcheck_text
呢?
...指示Solr您希望它復制添加到索引的文檔的“目標”字段中該文檔的“源”字段中看到的所有數據。 ...在調用任何為原始或目標字段配置的分析器之前, 原始文本將從“源”字段發送到“目標”字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.