solr智能提示 suggest(针对索引的某个字段建立索引词库做智能提示)

    xiaoxiao2021-03-25  108

    solr1.4以后实现的智能提示,方便用户输入搜索

    Suggest配置

    solrconfig.xml

    <searchComponent name="suggest" class="solr.SpellCheckComponent"> <str name="queryAnalyzerFieldType">string</str> <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">city</str> <float name="threshold">0.0001</float> <!--<str name="sourceLocation">suggest_dict.txt</str>--> <!-- <str name="spellcheckIndexDir">spellchecker</str> --> <str name="comparatorClass">freq</str> <str name="buildOnOptimize">true</str> <!--<str name="buildOnCommit">true</str>--> </lst> </searchComponent> <requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy"> <lst name="defaults"> <str name="spellcheck">true</str> <str name="spellcheck.dictionary">suggest</str> <str name="spellcheck.onlyMorePopular">true</str> <str name="spellcheck.extendedResults">false</str> <str name="spellcheck.count">10</str> <str name="spellcheck.collate">true</str> </lst> <arr name="components"> <str>suggest</str> </arr> </requestHandler>

    说明:

    1.solr的suggest基于solr.SpellCheckComponent

    2.queryAnalyzerFieldType 参数为string,在这不要定义复杂分词,如果是根据某一个索引字段,意义不大

    3.field字段名,表示基于schema中的某一个索引字段

    4.threshold限制一些不常用的词出现,值越大过滤纸越多

    5.sourceLocation用于设置字典,如果有一个字典能记录用户常搜索的字,那提示更更好

    6.spellcheckIndexDir如果已经设置spellcheck,那么可以在此制定目录

    7.字典格式如下

    #This is a sample dictionary file. acquire accidentally\t2.0 accommodate\t3.0

    文本格式utf-8,#开头表示注释,被忽略

    每一个词一行,后面带权重

    8.配置词典后在requestHandler中设置spellcheck.onlyMorePopular为true,可以根据权重排序

    9.spellcheck.count返回行

    schema.xml配置:

    <!-- 名称 --> <field name="city" type="text_ik" indexed="true" stored="true"/> <!-- 目标域--> <field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/> <!-- 添加到目标域--> <copyField source="city" dest="item_keywords"/>

    请求地址:http://localhost:8080/solr/suggest?q=北

    转载请注明原文地址: https://ju.6miu.com/read-12740.html

    最新回复(0)