Query Expansion
A user searches for “couch.” The documents say “sofa.” Without query expansion, no results. With it, the search system understands that “couch” and “sofa” are synonyms and expands the query to match either. This seemingly simple addition improves recall dramatically, but introduces its own set of problems.
Synonym Expansion#
The most basic form: maintain a synonym dictionary. Before executing the query, expand each term with its synonyms.
"couch" → ["couch", "sofa", "settee", "loveseat"]
Query: "buy couch" becomes:
(buy) AND (couch OR sofa OR settee OR loveseat)
Synonym dictionaries are domain-specific. A general thesaurus includes too many loosely related terms. “Bank” expands to “river bank,” “bank vault,” and “financial institution.” Without domain context, over-expansion adds noise. Search teams maintain curated synonym files for their domain.
Spell Correction#
Users misspell queries constantly. “distrbuted systems” gets no results for the correct documents. Spell correction rewrites the query before search.
Edit distance (Levenshtein distance) between the query term and dictionary terms finds candidates. “distrbuted” has edit distance 1 from “distributed” (one transposition). But checking every dictionary word against every query term is O(N) per term. Too slow.
BK-trees or SymSpell speed this up: index the dictionary by edit distance so lookups are O(log N) or O(1) average. SymSpell precomputes all terms within edit distance 1 and 2 at dictionary-build time, making query-time correction O(1) at the cost of a large precomputed structure.
Query Intent and Reformulation#
More powerful than synonym expansion: learning from click data what users actually meant. If users who searched “buy couch” clicked on results for “sofa purchase,” that’s a signal that these queries have equivalent intent. Learned query-to-query mappings can rewrite queries based on historical click behavior, without needing a hand-curated synonym dictionary.
This is query reformulation at scale: aggregate click logs, find queries with high result overlap, build a mapping. Needs large query volume to have enough signal per query.
The Recall-Precision Trade-Off#
More expansion = higher recall (more relevant results found). But it also means more irrelevant results (lower precision). “run” expands to “execute,” “sprint,” “jog,” “operate.” For some queries that’s fine; for others it’s too broad.
Handling this: apply expansion conservatively for short queries (where the user likely wants broad results) and less aggressively for long, specific queries (where the user knows what they want).
At Oracle#
Our internal ticket search had terrible recall because engineers used abbreviations (NSSF, PCSCF, IMS) that weren’t in the index because tickets were filed using full names. We built a custom abbreviation expansion table from documentation: NSSF → “Network Slice Selection Function.” Adding this to the query pipeline increased relevant ticket retrieval by 40% in user testing. Domain-specific expansion outperformed generic approaches by a wide margin.
What I’m Learning#
Query expansion is where linguistic knowledge meets information retrieval. The systems challenge is doing it fast (all expansion must happen before the search query, adding at most a few milliseconds) and doing it without over-expanding into irrelevance.
Have you worked with search systems where domain-specific query understanding made a larger impact than improving the underlying search algorithm?