You need to configure the spellchecker component to generate alternative spelling options, as described at http://wiki.apache.org/solr/SpellCheckComponent
The task consists of the following steps: - Refresh schema.xml to suggest spelling, for example, you can copy fields to a new field, for example, "spelling", for example,
<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" />
- Update solrconfig.xml file
<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 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>
Retell the case
Testing recommendations, for example,
Http: //: / Solr / select / d = 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"]}]}}
Hope this helps.
Nitin tripathi
source share