如何让Solr Suggester返回拼写建议

时间:2012-06-15 08:27:43

标签: apache solr autosuggest

我目前正在将Apache Solr搜索集成到我的平台中,并使用Suggester功能进行自动完成。但是,建议模块也不会返回拼写建议,例如,如果我搜索:

shi

建议模块返回以下内容:

shirt
shirts

但是,如果我搜索:

shrt

不会返回任何建议。我想知道的是:

a)建议模块的配置是否错误导致了这种情况? b)建议者模块是否以不返回拼写建议的方式构建? c)如何让Suggester模块返回拼写建议,而无需再提出拼写纠正建议请求?

我已经阅读了Solr文档,但似乎无法取得进展。

1 个答案:

答案 0 :(得分:8)

您需要配置拼写检查组件以生成http://wiki.apache.org/solr/SpellCheckComponent

中所述的备用拼写选项

该任务包括以下步骤;   - 更新用于拼写建议的schema.xml,就像您可能希望将字段复制到新字段中,例如“拼写”。

<copyField source="id" dest="spelling" />
<copyField source="name" dest="spelling" />
<copyField source="description" dest="spelling" />
<copyField source="longdescription" dest="spelling" />
<copyField source="category" dest="spelling" />
<copyField source="source" dest="spelling" />
<copyField source="merchant" dest="spelling" />
<copyField source="contact" dest="spelling" />
  • 更新solrconfig.xml

<requestHandler name="/select" class="solr.SearchHandler"> <lst name="defaults"> <str name="echoParams">explicit</str> <int name="rows">10</int> <str name="df">defaultSearchField</str> <!-- spell check component configuration --> <str name="spellcheck">true</str> <str name="spellcheck.count">5</str> <str name="spellcheck.collate">true</str> <str name="spellcheck.maxCollationTries">5</str> </lst> <!-- add spell check processing after the default search component as configured above completed it's task --> <arr name="last-components"> <str>spellcheck</str> </arr> </requestHandler>

<searchComponent name="spellcheck" class="solr.SpellCheckComponent"> <lst name="spellchecker"> <!-- decide between dictionary based vs index based spelling suggestion, in most cases it makes sense to use index based spell checker as it only generates terms which are actually present in your search corpus --> <str name="classname">solr.IndexBasedSpellChecker</str> <!-- field to use --> <str name="field">spelling</str> <!-- buildOnCommit|buildOnOptimize --> <str name="buildOnCommit">true</str> <!-- $solr.solr.home/data/spellchecker--> <str name="spellcheckIndexDir">./spellchecker</str> <str name="accuracy">0.7</str> <float name="thresholdTokenFrequency">.0001</float> </lst> </searchComponent>

  • 重新索引语料库

  • 测试建议,例如

    的http://:/ solr的/选择/ Q = coachin

    response { "responseHeader":{ "status":0, "QTime":12, "params":{ "indent":"true", "q":"coachin"}}, "response":{"numFound":0,"start":0,"docs":[] }, "spellcheck":{ "suggestions":[ "coachin",{ "numFound":1, "startOffset":0, "endOffset":7, "suggestion":["cochin"]}]}}

希望有所帮助。

相关问题