Source: Classical IR literature (Manning et al.); production patterns across search platforms; Grainger, AI-Powered Search
Classification — Rule-based and learned query rewriting that alters the query before retrieval.
Improve retrieval quality by transforming the user's query — removing low-value tokens, reformulating into structured forms, reducing overly-long queries — in ways that improve match quality without losing user intent.
Raw user queries often need modification before they're ideal for retrieval. Stop words ("the", "and", "of") contribute little to matching but add noise; removing them helps in most cases but hurts when they're part of phrases ("to be or not to be" needs the stop words). Long queries ("I'm looking for a really comfortable pair of black running shoes for marathon training that don't cost too much") don't match well at full length — too few documents contain all the terms. Specific phrasings ("red shoes") have implicit structure (color = red, category = shoes) that the retrieval system can use only if it's made explicit. Query rewriting handles these cases.
Stop word removal. Identify and remove low-value tokens from the query. Lucene and similar libraries provide language-specific stop word lists (English: a, an, the, and, or, of, in, on, ...). The removal happens in the analyzer chain (Section A). The pattern is appropriate for most cases but breaks for phrase queries where stop words are essential: "to be or not to be" loses its identity if stops are removed. Production systems often have multiple analyzer chains: stop-word-removing for general matching, stop-word-preserving for phrase matching, with appropriate query construction to use each.
Stop word handling for short queries. A short query that's entirely stop words ("where is", "what is") becomes empty after stop word removal, retrieving nothing. Production patterns: detect this case and fall back to preserving stops; or rewrite the query to add a synthetic non-stop-word; or trigger a different retrieval path that handles the case. The edge case is small but matters because users get confused when extremely short queries fail.
Query reformulation rules. Explicit rules that transform query patterns into structured queries. "red running shoes" might be rewritten as "color:red category:running_shoes" where the structured fields apply as boosts or filters. "Size 10 mens" might extract size=10, gender=mens as structured signals. The rules typically pattern-match against the query (after tokenization and entity recognition) and apply transformations. Production systems maintain rule sets ranging from dozens to thousands of rules depending on workload complexity.
Rule sources. Manual: domain experts encode known patterns. Learned: query log analysis surfaces common patterns where specific reformulations would have helped. LLM-suggested: prompt the model for likely reformulations of common queries. Production deployments often combine: manual rules for known high-value cases, learned rules for the long tail, LLM suggestions for new query types.
Query reduction. Long queries don't match well — too few documents contain all the terms. Reduction identifies the most important terms and drops the rest. Methods: IDF-weighted importance (keep high-IDF terms, drop low-IDF); entity-aware reduction (keep recognized entities, drop filler); learned reduction (a model trained to predict which terms to keep). The reduction is often applied as fallback: try the full query first; if too few results, retry with reduced query. Some systems run both in parallel and combine.
Phrase recognition. Multi-word phrases ("New York Times") should sometimes be treated as units rather than independent tokens. Phrase recognition identifies likely multi-word entities and treats them as quoted phrases. Methods: gazetteer-based (lookup against known multi-word entities); learned (a model trained on phrase-vs-not-phrase distinctions); LLM-based (prompt the model to identify phrases). The pattern is essential for proper noun handling and specific product/brand recognition.
Reformulation evaluation. Query rewrites change retrieval behavior; the changes need to be evaluated. The methodology from Volume 5: track per-rewrite metrics (does this rule improve outcomes for the queries it triggers on?); maintain golden query sets that include rewritten cases; A/B test substantial rule additions or changes. Production teams without evaluation discipline often accumulate rules that individually look helpful but collectively degrade quality; evaluation discipline prevents this drift.
Production search where user queries vary substantially in length, structure, and formality. E-commerce, enterprise search, customer service search, technical documentation search. Cases where query log analysis surfaces patterns that consistent rewriting would handle.
Alternatives — no rewriting (raw queries) for cases where users issue clean structured queries (advanced search interfaces, API search). LLM-based query rewriting (next-generation pattern) for cases needing context-aware transformations. Most production search benefits from some rewriting; the level of investment depends on workload complexity.
- Manning et al., Introduction to Information Retrieval, ch. 2
- Grainger, AI-Powered Search, chapters on query rewriting
- Coveo query pipeline documentation
- Algolia query rules documentation