Managing spell correction
Spell correction is automatically triggered when a shopper searches for misspelled words.
When a query with misspelled words returns no results, a second query that contains the
top suggested terms is run by default.
Procedure
-
Update spell checker values in the solrconfig.xml file:
Spell correction in HCL Commerce Search uses Solr spellCheckComponent, defined in the solrconfig.xml file:
<searchComponent name="wc_spellcheck" class="solr.SpellCheckComponent">
-
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.
-
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:
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.<!-- Spell correction field --> <field name="spellCorrection" type="wc_textSpellCorrection" indexed="true" stored="false" multiValued="true" />
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> <analyzer type="query"> <tokenizer class="solr.WhitespaceTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/> </analyzer> </fieldType>
-
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 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 theFor more information about the spell check properties, see Search properties in the component configuration file (wc-component.xml).OR
search operator. If you are using theAND
search operator and prefer to display only relevant suggestions, consider setting theSpellCheckQueryOperator
property toAND
.Note: Using theOR
operator relaxes the conditions to find spell check corrections, while using theAND
operator produces fewer or no spell check corrections.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