Fuzzy Search
ELI5 — The Vibe Check
Fuzzy search finds results even when the search term is misspelled or slightly off. Search for 'jonh' and it still finds 'John.' It uses algorithms that measure how similar two strings are. Perfect for search bars where users can't spell.
Real Talk
Fuzzy search finds approximate matches rather than exact matches, using string similarity algorithms like Levenshtein distance, Jaro-Winkler, or trigram similarity. In PostgreSQL, the pg_trgm extension enables trigram-based fuzzy search with GIN/GiST indexes. Elasticsearch provides fuzzy queries with configurable edit distance. Essential for user-facing search with typo tolerance.
Show Me The Code
-- PostgreSQL with pg_trgm
CREATE EXTENSION pg_trgm;
SELECT name, similarity(name, 'jonh') as sim
FROM users
WHERE name % 'jonh' -- trigram similarity > threshold
ORDER BY sim DESC;
When You'll Hear This
"Enable fuzzy search so typos like 'iphne' still find 'iPhone'." / "We use pg_trgm for fuzzy search instead of Elasticsearch — simpler for our scale."
Related Terms
Full-Text Search
Full-text search lets you search through text like Google does, not just exact matches.
GIN Index
A GIN index is like a book's index on steroids. Instead of pointing to one location per entry, each entry can point to thousands of locations.
Trigram Search
Trigram search breaks words into groups of three letters and matches them fuzzily.