Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Fuzzy search

Fuzzy search

Lucene includes functionality for performing fuzzy searches. A fuzzy search searches for terms that are similar but not exactly equal to the terms specified by the user. Elastic Path uses fuzzy search functionality to look for possible results when exact matches are not found.

Fuzzy searches

Fuzzy search uses the Search Settings system setting.

The minimum similarity value is a value between 0 and 1 that sets the required similarity between the query term and the matching terms. For example, if COMMERCE/SEARCH/minimumSimilarity is set to 0.5, a term of the same length as the query term is considered similar to the query term if the edit distance between both terms is less than length(term)*0.5, where edit distance is a measure of similarity between two strings and distance is measured as the number of character deletions, insertions, or substitutions required to transform one string to the other string.

For example, the edit distance between "kitten" and "sitting" is 3, since these three edits change one into the other, and there is no way to do it with fewer than three edits:

  1. kitten ? sitten (substitution of 'k' for 's')
  2. sitten ? sittin (substitution of 'e' for 'i')
  3. sittin ? sitting (insert 'g' at the end)

Key classes and files

  • SolrIndexSearcher - A data access object for Lucene searching. This class contains logic for executing fuzzy searches when no exact matches are found.
  • ProductQueryComposer - Implements a method, composeFuzzyQuery(..), that creates a new FuzzyQuery Lucene object. The object is populated with the search terms and configuration options specified in the search settings.