我想使用solr爲搜索字段創建一個autosuggestion下拉菜單,但當我嘗試獲取短語的建議時,我陷入了困境。當我搜索「狗t」時,我想要得到一個結果集,其中包含諸如「狗處理」,「狗技巧」,「狗標記」等短語,但是我得到2個結果集,一個用於「狗」 「(如‘狗’,‘狗骨頭’,‘狗’......),另一個是‘T’(如‘樹’的‘時間’......)get solr autosuggest結果短語
我查詢網址是:
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>