我想使用 solr 为搜索字段创建自动建议下拉列表,但在尝试获取短语建议时遇到了困难。当我搜索“dog t”时,我想得到一个包含诸如“dog Treat”、“dog trick”、“dog tags”等短语的结果集,但是我得到了2个结果集,一个是“dog "(例如“dogs”“dog bone”“doggy”...)和另一个用于“t”(例如“tree”“time”...)
我的查询网址是:
http://localhost:8985/solr/mycollection/suggest?q=%22dog%20t%22&wt=json
我的请求处理程序在 solrconfig 中定义为...
<searchComponent class="solr.SpellCheckComponent" name="suggest">
<lst name="spellchecker">
<str name="name">suggest</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
<str name="field">suggest</str> <!-- the indexed field to derive suggestions from -->
<float name="threshold">0.0001</float>
<str name="buildOnCommit">true</str>
</lst>
<str name="queryAnalyzerFieldType">textSuggest</str>
</searchComponent>
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
“建议”的字段类型在模式中定义为
<fieldType name="textSuggest" class="solr.TextField" positionIncrementGap="100" >
<analyzer type="index">
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ShingleFilterFactory" maxShingleSize="3" outputUnigrams="true" />
<filter class="solr.WordDelimiterFilterFactory"
generateWordParts="1"
generateNumberParts="1"
catenateWords="0"
catenateNumbers="0"
catenateAll="0"
preserveOriginal="1" splitOnCaseChange="1"
/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>