我使用IndexBasedSpellChecker配置了一个Solr拼写检查组件,其中包含一个包含国家/地区名称的核心:
<searchComponent name="indexBasedSpellCheck" class="solr.SpellCheckComponent">
<lst name="spellchecker">
<str name="name">indexBasedSpellCheck</str>
<str name="classname">solr.IndexBasedSpellChecker</str>
<str name="spellcheckIndexDir">./indexspellchecker</str>
<str name="field">name</str>
<str name="buildOnCommit">true</str>
<str name="distanceMeasure">org.apache.lucene.search.spell.LevensteinDistance</str>
<str name="accuracy">0.5</str>
</lst>
</searchComponent>
拼写检查的请求处理程序:
<requestHandler name="/index-spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="spellcheck.dictionary">idxBasedSpellCheck</str>
<str name="spellcheck">on</str>
<str name="spellcheck.extendedResults">true</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.alternativeTermCount">5</str>
<str name="spellcheck.maxResultsForSuggest">5</str>
<str name="spellcheck.collate">true</str>
<str name="spellcheck.collateExtendedResults">true</str>
<str name="spellcheck.maxCollationTries">10</str>
<str name="spellcheck.maxCollations">5</str>
</lst>
<arr name="last-components">
<str>indexBasedSpellCheck</str>
</arr>
</requestHandler>
当我要求时:
curl 'http://localhost:8983/solr/mycore/index-spell?indent=on&spellcheck.q=tanaz&wt=json&spellcheck.collate=true'
我得到的结果如下:
"spellcheck":{
"suggestions":[
"tanaz",{
"numFound":3,
"startOffset":0,
"endOffset":5,
"origFreq":0,
"suggestion":[{
"word":"canada",
"freq":1},
{
"word":"panama",
"freq":1},
{
"word":"tanzania",
"freq":1}]}],
"correctlySpelled":false,
"collations":[]}
为什么我的校对空了?我的请求中有spellcheck.collate = true。
答案 0 :(得分:1)
我认为您在请求中缺少df
(默认字段)参数。
在您的请求中添加df=name
:
您也可以在请求处理程序默认值中对此进行配置,因此您无需在请求中发送此内容。
<requestHandler name="/index-spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
...
<str name="df">name</str>
...
</lst>
<arr name="last-components">
<str>idxBasedSpellCheck</str>
</arr>
</requestHandler>