您需要配置拼写检查组件以生成备用拼写选项,如https://lucene.apache.org/solr/guide/8_1/spell-checking.html中所述
该任务包括以下步骤:
首先,schema.xml
使用拼写检查字段更新 。这通常意味着创建一个新字段并将多个字段复制到一个spellcheck
字段:
<field name="spellcheck" type="text_general"
indexed="true"
stored="false"
multiValued="true"/>
<copyField source="id" dest="spellcheck"/>
<copyField source="name" dest="spellcheck"/>
<copyField source="description" dest="spellcheck"/>
<copyField source="longdescription" dest="spellcheck"/>
<copyField source="category" dest="spellcheck"/>
<copyField source="source" dest="spellcheck"/>
<copyField source="merchant" dest="spellcheck"/>
<copyField source="contact" dest="spellcheck"/>
在solrconfig.xml
更新您的请求处理程序并创建一个solr.SpellCheckComponent
并将其添加到您的搜索处理程序中。
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<lst name="spellchecker">
<!-- decide between dictionary based vs index based spelling suggestions,
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">spellcheck</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>
<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. This is
the search component name. -->
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
http://localhost:8983/solr/select/?q=coachin
{
"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"]
}
]
}
}