The /select handler of your index runs the spellchecker after every search that asks for it. The corrections come from the words of your own pages, so the names of your products and places are corrected too.
01 · The parameters
spellcheck=true spellcheck.q=solr bakup spellcheck.count=5 spellcheck.collate=true spellcheck.maxCollations=3 spellcheck.maxCollationTries=15
spellcheck.q is the text as the visitor typed it. collate builds whole corrected searches, and maxCollationTries makes Solr check that a corrected search finds results before it offers it. These are the values the hosted search page sends.
02 · The dictionary
The words of the spell field, which Opensolr fills with the title, the description and the first words of the text of every page.
A suggestion is at most 2 letters away from the typed word.
Words shorter than 3 letters are left alone.
A word found in more than half of your documents is taken as spelled right.
03 · The response
"spellcheck": { "suggestions": ["bakup", {"numFound": 3, "startOffset": 5, "endOffset": 10, "suggestion": ["backup", "backups", "baked"]}], "collations": ["collation", "solr backup", "collation", "solr backups", "collation", "solr baked"] }
var c = data.spellcheck && data.spellcheck.collations; var suggestion = (c && c.length >= 2) ? c[1] : null; // "solr backup"
04 · When to show it
Show the suggestion when the search found few or no results. With many results, the visitor most likely spelled the words as intended. Put the text in the page with textContent, and run the corrected search when it is clicked. The hosted search page does the same: Did you mean.