Table of Contents

Suggestions

Step-by-Step Guide to implement 'Did You Mean'-suggestions

Dynamicwebs 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.

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 Free text search – 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

    • Field to check: Free text search
    • Query parameter: YourFreeTextSearchParameter

    Spell_Check

  3. In the Templates section create or edit the No product found template and render suggestions – see code below for an example:

<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>
To top