The Search Odyssey
In progress
Module 5Forgive the typo, protect the precision Fuzzy Finder

Fuzzy Search and Typo Tolerance

Measure string similarity with Levenshtein and Damerau-Levenshtein edit distance. Generate candidates efficiently with n-gram indexes, understand BK-trees and Levenshtein automata, and learn to tune tolerance to fix typos without flooding results with false matches.

Levenshtein distanceDamerau-LevenshteinDynamic programmingN-gramsTrigramsBK-treeLevenshtein automataTypo tolerance

The stumper

Searching "iphon 15 prro" returns nothing. How do we rescue it without matching unrelated terms?

Users mistype on phones and keyboards - transpositions ("teh"), missing letters, extra letters, wrong letters. Exact string equality punishes all of these. Good search engines are forgiving.

Edit distance gives a principled measure: minimum number of single-character insert/delete/substitute operations to transform string A to string B. Damerau-Levenshtein adds adjacent transpositions as cost 1, capturing the most common real errors.

We cannot compute edit distance against every document. Strategy: build an index of character n-grams (e.g., trigrams) for all terms. When query comes in, find terms sharing many n-grams as candidates, then run edit distance and filter by threshold.

Every bit of tolerance is a tradeoff. Loosen the threshold and recall for typos improves, but precision drops and computation increases. Short words are especially vulnerable to false positives.

Try it before you read on

Open the Lab tab. Change a parameter, break something, and form a hypothesis before reading the explanation.

Checkpoint

3 questions. Explanations appear after submission.

1. What does Levenshtein distance count?

2. What is the main risk of increasing the fuzzy distance threshold?

3. Why use n-grams?