基于Solr词典的建议器不会建议整个短语

时间:2014-01-06 13:00:23

标签: solr autocomplete search-suggestion

当我输入包含多个单词的查询到我的建议器组件时,我得到了每个单独的结果。这个问题在这里得到了很好的解释:How to have Solr autocomplete on whole phrase when query contains multiple terms?

唯一的区别是,我有一个基于字典文件的建议,而不是索引字段。上面链接中解释的解决方案和许多其他方法都不起作用

以下是配置:

<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.fst.AnalyzingInfixLookupFactory</str>
        <str name="buildOnCommit">true</str>
        <str name="suggestAnalyzerFieldType">text_suggest</str>
        <str name="sourceLocation">suggestionsFull.txt</str>
    </lst>
    <str name="queryAnalyzerFieldType">text_suggest</str>
    <!-- <queryConverter name="queryConverter" class="org.apache.solr.spelling.SuggestQueryConverter"/> -->
</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">5</str>
        <str name="spellcheck.collate">false</str>
    </lst>
    <arr name="components">
        <str>suggest</str>
    </arr>
</requestHandler>

schema.xml中

<fieldType name="text_suggest" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.TurkishLowerCaseFilterFactory"/>
        <filter class="solr.TrimFilterFactory"/>
    </analyzer>
</fieldType>

我还使用spellcheck.q参数代替q

http://localhost:8983/solr/collection1/suggest?spellcheck.q=bu+bir&wt=json&indent=true

我做错了什么?

1 个答案:

答案 0 :(得分:4)

最后我找到了解决方案:

即使您从文件而不是索引字段构建建议字典,您也必须在solrconfig中指定索引字段。因此,schema.xml在我们已创建的text_suggest字段类型中创建一个虚拟字段:

<field name="text_suggest" type="text_suggest" indexed="false" stored="false" />

然后在solrconfig.xml添加<str name="field">text_suggest</str>行到searchComponent

<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.fst.AnalyzingInfixLookupFactory</str>
          <str name="buildOnCommit">true</str>
          <str name="suggestAnalyzerFieldType">text_suggest</str>
          <str name="field">text_suggest</str>
          <str name="sourceLocation">suggestionsFull.txt</str>
       </lst>
    </searchComponent>

重启solr,你就完成了!