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


Procedure

  1. Update spell checker values in the solrconfig.xml file: Spell correction in WebSphere Commerce Search uses Solr 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:

        name
        The name of the SpellChecker to use.

        field
        The field that its contents is used to build the SpellChecker result.

        classname
        The SpellChecker implementation class.

        distanceMeasure
        The algorithm used to calculate the terms distance.

        accuracy
        The level of precision that must be reached for the suggestion to be considered.

        maxEdits
        The maximum number of changes during term enumeration. This value is typically set to 1 or 2.

        minPrefix
        The minimum common prefix during term enumeration.

        maxInspections
        The maximum number of checks for each suggestion.

        minQueryLength
        The minimum suggestion length for the word to be considered as a suggestion.

        maxQueryFrequency
        The maximum percentage of documents in which suggestions appear for the word to be considered as correct.

        thresholdTokenFrequency
        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>
            </lst>

  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 that are 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 suggests three 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. 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 alternative search terms are suggested. We 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>
            <analyzer type="query">
             <tokenizer class="solr.WhitespaceTokenizerFactory"/>
             <filter class="solr.LowerCaseFilterFactory"/>
             <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
            </analyzer>
        </fieldType>

  4. Testing and working with spell correction in the catalog:

    Spell correction searches for all products across the entire master catalog and all sales catalogs by default. We can limit it to the current sales catalog using the SpellCheckCollatedResultsOnly setting in the wc-component.xml file. Spell checks are performed against all terms in the q field of the Solr query by default using the OR search operator. If we are using the AND search operator and prefer to display only relevant suggestions, consider setting the SpellCheckQueryOperator property to AND.

    Note: Using the OR operator relaxes the conditions to find spell check corrections, while using the AND operator produces fewer or no spell check corrections. For more information about the spell check properties, see Search properties in the component configuration file (wc-component.xml). For example, the following URL calls Solr, using the searchTerm you entered, to request five similar phrases (searchable links) to be returned, by using a predefined algorithm (solrconfig.xml) on the fields specified (schema.xml):

      http://solr_hostname:3737/solr/MC_masterCatalogID_CatalogEntry_locale
      /select?q=name:searchTERM&spellcheck.count=5&spellcheck=true&spellcheck.collate=false


Related concepts
Automatic search term suggestions and spelling correction