solr4.9

自动完成配置问题记录

<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.TSTLookupFactory</str>
<!-- Alternatives to lookupImpl:
org.apache.solr.spelling.suggest.fst.FSTLookupFactory [finite state automaton]
org.apache.solr.spelling.suggest.fst.WFSTLookupFactory [weighted finite state automaton]
org.apache.solr.spelling.suggest.jaspell.JaspellLookupFactory [default, jaspell-based]
org.apache.solr.spelling.suggest.tst.TSTLookupFactory [ternary trees]
-->
<str name="field">AllContent</str> <!-- the indexed field to derive suggestions from -->
<float name="threshold">0.005</float>
<str name="buildOnCommit">true</str>
<!-- 使用自定义suggest词库词 -->
<str name="sourceLocation">suggest.txt</str>
<!-- <str name="spellcheckIndexDir">spellchecker</str> -->
</lst>
</searchComponent>


这里的suggest.txt词库默认应该是

utf-8 无BOM文档,否则solr读取有问题,

如果utf-8有BOM,那么词库第一行无法读取:

solr 4.9 suggest.txt词库默认应该是utf-8 无BOM文档_apache


solr suggest 自定义词库和系统词库一起使用:

<!-- 可以定义多个,name查询spellchecker -->
<lst name="spellchecker">
<str name="name">suggestcustom</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookupFactory</str>
<str name="field">AllContent</str>
<float name="threshold">0.005</float>
<str name="buildOnCommit">true</str>
<!-- 使用自定义suggest词库词 -->
<str name="sourceLocation">suggest.txt</str>
<!-- <str name="spellcheckIndexDir">spellchecker</str> -->
</lst>


查询方式:http://localhost:8080/solr/resource/suggest?q=全&wt=json&indent=true&spellcheck=true&spellcheck.build=true&spellcheck.reload=true

&spellcheck.dictionary=suggest&spellcheck.dictionary=suggestcustom