Suggestions

As of Dynamicweb 9.8 the Indexing engine supports ‘Did You Mean’-suggestions – this helps users find what they are looking for even if they make a minor spelling mistake or are not certain how a search term is spelled (Figure 1.1).

Figure 1.1 Suggestions

At the technical level, we apply the Lucene SpellChecker against an index document field and – based on the available terms in that field for all documents – find the closest matches using several distance filters.

Implementing “Did you mean”-suggestions is very easy – let’s say you have a free-text search on a website where users search in the following fields:

  1. Product name
  2. Product number
  3. Variant options
  4. Short description
  5. Long description

For simplicity’s sake these fields have been added to a Summary-field called FreeText – and you want to provide suggestions to a user whenever they search for a term which can’t be found in the index.

  1. Open the product catalog app used to publish your products
  2. Find the Spell Check section and configure it (Figure 1.2):
    • Field to check: FreeText
    • Query parameter: Search – or whatever your free-text search parameter is called
Figure 1.2 The Spell Check section
  1. In the Templates section create or edit the No product found template and render suggestions – see code below for an example:
RAZOR
<div class="row"> <div class="col-md-12"> @{ string pageid = GetString("Ecom:ProductList:Page.ID"); string firstSuggestion = GetString("QueryResult.SpellCheck"); } @if (!string.IsNullOrWhiteSpace(firstSuggestion)) { <strong>Did you mean: </strong> <a href="Default.aspx?ID=@pageid&Search=@firstSuggestion"><i>@firstSuggestion</i></a><br /> foreach (var suggestion in GetLoop("SpellCheckerSuggestions")) { var suggestionTerm = suggestion.GetString("Suggestion"); <a href="Default.aspx?ID=@pageid&Search=@suggestionTerm" style="margin-right:5px;color: #AAAAAA !important; font-size: 12px !important">@suggestionTerm</a> } } </div> </div>