Discover what fuzzy search is with fuzzy matching

Peter Villani4 Feb 2022

Problem

Product search that matches only exact words fails in everyday cases. A user types "canou" for "canoe" and gets nothing. A shopper writes "trousers" while the catalog says "pants", or types a long query that no single record contains. Loosening the match fixes this, but too much looseness returns piles of results or odd ones that make users doubt the whole search.

Example from the article: a clothing store index where a search for "slacks" should return only "pants" and "trousers", not the other meanings of the word (laziness, looseness).

Solution in brief

Add several controlled kinds of inexact matching on top of exact text matching: typo tolerance by edit distance, synonyms, prefix and partial-word matching, optional words, word removal and optional filters. Cap each one (distance at most 2, a small curated synonym list) and rank exact matches above fuzzy ones.

Questions this case answers
  • How to widen query-to-record matching beyond exact strings (typos, vocabulary mismatch, partial words) without drowning exact matches in weaker ones
  • How to make product search return results when users mistype a word?
  • How to let users search in their own words (pants vs trousers) without flooding results with irrelevant matches?
  • How to avoid zero-result pages when a query has too many words or words missing from the catalog?

Tools and methods

  • Damerau–Levenshtein distance — counts the edits between a typed word and an indexed word to decide whether it is a typo
  • Synonyms — a curated list of words the engine treats as equal
  • Prefix search — matches partial words so results appear as the user types
  • Optional words and word removal — let a record match when only some query words match
  • Optional filters — add non-matching records but rank them lower
  • Algolia — the search engine whose behavior the article describes
Continue reading — it's free

Google or a one-time email code. No password.