This time I would like to tell you about the new “Did you mean” functionality that we recently incorporated into our “Product Search, Extended” module. This functionality allows displaying search query suggestions by correcting the misspelled keywords according to the information available in the search index. This will become available with Dynamicweb 8.1 (release is scheduled for May, 2012).
How it works
The “Did you mean” functionality uses Java port of Lucene’s SpellChecker module (originally being a part of Lucene core but continued as a separate project). The module itself uses various algorithms of determining how the misspelled word can be corrected. In particular, it provides implementations of several algorithms for measuring similarity between words. Among available implementations are Levenshtein distance (which we use), Jaro–Winkler distance, and couple others.
After your search index is updated (either by using the GUI or by performing a direct API calls), we execute the code that triggers SpellChecker to rebuild a grammar dictionary which will be used later for correcting spelling mistakes (the grammar dictionary resides in /Files/System/_search/Products/spelling folder). You don’t need to change any settings in a backend in order to activate SpellChecker.
The system checks for the “eComQuery” query-string parameter in order to retrieve search phrase that needs to be corrected. If you use free text search filter instead, the system will take the first one that has a value and use that value instead (but remember that the “eComQuery” has a higher priority).
No spelling corrections are provided if there are any products that are found.
How to use it
There is a bunch of new template tags that are available in search template as well as in “No products” template. These tags are also available in free text search filter template. Here they are:
|Ecom:Search.HasSpellingCorrections||Indicates whether search phrase is misspelled.|
|Ecom:Search.SpellingCorrections||Spelling corrections loop.|
|Ecom:Search.SpellingCorrection.OriginalPhrase||Original search phrase.|
|Ecom:Search.SpellingCorrection.CorrectedPhrase||Corrected search phrase.|
|Ecom:Search.SpellingCorrection.Keywords||Loop containing keywords for a given spelling correction.|
|Ecom:Search.SpellingCorrection.Keyword.Index||Zero-based index of the keyword within the phrase.|
|Ecom:Search.SpellingCorrection.Keyword.IsFirst||Indicates whether this is a first keyword within the phrase.|
|Ecom:Search.SpellingCorrection.Keyword.IsLast||Indicates whether this is a last keyword within the phrase.|
|Ecom:Search.SpellingCorrection.Keyword.IsCorrected||Indicates whether this is either corrected or original keyword.|
|Ecom:Search.BestSpellingCorrection.OriginalPhrase||Original search phrase.|
|Ecom:Search.BestSpellingCorrection.CorrectedPhrase||Corrected search phrase.|
|Ecom:Search.BestSpellingCorrection.Keywords||Loop containing keywords for a given spelling correction.|
|Ecom:Search.BestSpellingCorrection.Keyword.Index||Zero-based index of the keyword within the phrase.|
|Ecom:Search.BestSpellingCorrection.Keyword.IsFirst||Indicates whether this is a first keyword within the phrase.|
|Ecom:Search.BestSpellingCorrection.Keyword.IsLast||Indicates whether this is a last keyword within the phrase.|
|Ecom:Search.BestSpellingCorrection.Keyword.IsCorrected||Indicates whether this is either corrected or original keyword.|
As you can see there might be several different spelling correction alternatives for a given phrase so there is a loop called “Ecom:Search.SpellingCorrections”. Tags starting with “Ecom:Search.BestSpellingCorrection.” represents a best (most relevant) spelling correction.
For free text search filter all above tags must start with “Ecom:Filters.Text” (and not with “Ecom:Search.”).
Here is an example of how it works in a frontend (“No products” template which uses new tags):
We hope that you will like the new functionality. Use our forum if you have any questions/problems.