假设用户搜索以下内容:
red computor
"red"拼写正确,但"computor"拼写错误。我有以下拼写检查器的配置:
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">spelling</str>
<str name="classname">solr.IndexBasedSpellChecker</str>
<str name="accuracy">0.5</str>
<int name="maxEdits">2</int>
<int name="minPrefix">1</int>
<int name="maxInspections">5</int>
<int name="minQueryLength">3</int>
</lst>
我发出的查询如下:
http://localhost:8983/solr/collection1/spell?q=computor+red&wt=json&indent=true&spellcheck=true&spellcheck.collate=true
因为"红色"拼写正确,我得到了与"红色"相关的文档的结果,但我没有得到拼写错误的术语"computor"的任何拼写建议。如果我把"red"改成不正确的单词,比如"reeed",我会得到"reed"one_answers"computor"的拼写建议,但如果一个术语看起来拼写正确,那么我根本没有得到任何建议。
如何重新配置我的查询或拼写检查器,以便对查询中的每个传入术语运行拼写检查器?
我也遇到过类似的问题,但已经找到了使用solr的解决方案。
如果您使用的是旧版本,请首先将solr版本升级到最新的solr-6.1.0。
如果您使用的是IndexBasedSpellChecker,那么您的文档中应该有单词computer。通过字段类型中的index="true"。
对于正确的拼写检查更改,
accuracy => 0.001
minCount => 1
maxCollationTries => 1
maxCollations => 1
如果现在不需要,请将其删除
<int name="maxEdits">2</int>
<int name="minPrefix">1</int>
<int name="maxInspections">5</int>
在indexBasedSpellcheckerComponent,下添加此代码
<!-- a spellchecker that can break or combine words. See "/spell" handler below for usage -->
<lst name="spellchecker">
<str name="name">wordbreak</str>
<str name="classname">solr.WordBreakSolrSpellChecker</str>
<str name="field">spelling</str>
<str name="combineWords">true</str>
<str name="breakWords">true</str>
<int name="maxChanges">10</int>
</lst>
<!-- Example of using different distance measure -->
<lst name="spellchecker">
<str name="name">spelling</str>
<str name="field">lowerfilt</str>
<!-- Use a different Distance Measure -->
<str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str>
<str name="spellcheckIndexDir">./spellchecker</str>
</lst>
希望这能帮助到你。
您需要增加参数spellcheck.maxResultsForSuggest
的值,如果有"足够"的搜索结果,这将阻止建议。例如,尝试添加到您的配置中:
<int name="maxResultsForSuggest">500</int>