Introduced in Feature Pack 2

Working with spell correction

Spell correction (Did you mean?) is automatically triggered when a shopper searches for misspelled words. When a query with misspelled words returns no results, a second query containing the top suggested terms is run by default.


  1. Update spell checker values in the solrconfig.xml file:
    Spell correction in WebSphere Commerce search uses Solr's spellCheckComponent, defined in the solrconfig.xml file:
    <searchComponent name="wc_spellcheck" class="solr.SpellCheckComponent">
    1. Update the spell checker values to suit your business needs:
      The name of the SpellChecker to be used.
      The field that its contents is used to build the SpellChecker result.
      The SpellChecker implementation class.
      The algorithm that is used to calculate the terms distance.
      The level of precision that must be reached for the suggestion to be considered.
      The maximum number of changes during term enumeration. This value is typically set to 1 or 2.
      The minimum common prefix during term enumeration.
      The maximum number of checks for each suggestion.
      The minumum suggestion length for the word to be considered as a suggestion.
      The maximum percentage of documents in which suggestions appear for the word to be considered as correct.
      The minimum percentage of documents in which suggestions must appear in.
    2. Update the spell checker that reads the list of words from a file:
          <lst name="spellchecker">
             <str name="classname">solr.FileBasedSpellChecker</str>
             <str name="name">file</str>
             <str name="sourceLocation">spellings.txt</str>
             <str name="characterEncoding">UTF-8</str>
             <str name="spellcheckIndexDir">spellcheckerFile</str>
  2. Update spell checker values in the wc-component.xml file to suit your business needs:
    Note: Parameters that are defined in the wc-component.xml file overwrite the values defined in the solrConfig.xml by default.
    <_config:property name="SpellCheckMaxResultsForSuggestion" value="3" />
    <_config:property name="SpellCheckAlternativeTermCount" value="2" />
    <_config:property name="SpellCheckOnlyMorePopular" value="" />
    <_config:property name="SpellCheckMaxCollations" value="1" />
    <_config:property name="SpellCheckMaxCollationTries" value="2" />

    Where, for example, the SpellCheckMaxResultsForSuggestion value defines that the storefront will suggest 3 products by default.

  3. Update spell checker values in the schema.xml file to suit your business needs.

    Fields in the schema.xml file use spell correction values by default to work with spell correction behavior.

    For example, in the schema.xml file:
        Spell correction field
    <field name="spellCorrection" type="wc_textSpellCorrection" indexed="true" stored="false" multiValued="true" />
    The spellCorrection field is of type wc_textSpellCorrection, and the following indexed fields are assigned to it: name, shortDescription, keyword, nameOverride, shortDescriptionOverride, keywordOverride. As a result, Solr looks up these fields when suggesting alternative search terms.
    You can add more fields to suit your business needs:
    <!-- Copy fields for spell correction -->
     <copyField source="name" dest="spellCorrection"/>
     <copyField source="shortDescription" dest="spellCorrection"/>
     <copyField source="keyword" dest="spellCorrection"/>
     <copyField source="nameOverride" dest="spellCorrection"/>
     <copyField source="shortDescriptionOverride" dest="spellCorrection"/>
     <copyField source="keywordOverride" dest="spellCorrection"/>
    <!-- Spell correction text field -->
       <fieldType name="wc_textSpellCorrection" class="solr.TextField" positionIncrementGap="100">
          <analyzer type="index">
           <tokenizer class="solr.WhitespaceTokenizerFactory"/>
           <filter class="solr.LowerCaseFilterFactory"/>
           <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
          <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
          <analyzer type="query">
           <tokenizer class="solr.WhitespaceTokenizerFactory"/>
           <filter class="solr.LowerCaseFilterFactory"/>
           <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
  4. Testing and working with spell correction in your catalog:

    Spell correction searches for all products across the entire master catalog and all sales catalogs by default. You can limit it to the current sales catalog by adding spell checkers for each catalog that you want to search. For more information, see Limiting auto suggestions and spell corrections to a specific catalog.

    Spell checks are performed against all terms in the q field of the Solr query by default, including any functions passed in. You can specify which terms to check against by injecting the spellcheck.q parameter into the Solr query. For more information, see Adding query or filter query parameters to the final Solr query.

    For example, the following URL calls Solr, using the searchTerm you entered, to request 5 similar phrases (searchable links) to be returned, using a predefined algorithm (solrconfig.xml) on the fields specified (schema.xml):