Query Rewriting for Ecommerce Search: How It Works
A shopper searches "winne glases" and gets nothing back, even though the store sells wine glasses. The catalog has the product. The search bar just couldn't connect the two. Query rewriting is the mechanism that closes that gap — it's what happens between a shopper hitting enter and a results page appearing, when the system reshapes the query before matching it against the catalog instead of matching it literally and giving up.
What Is Query Rewriting?
Query rewriting is the step where a search system modifies, corrects, expands, or reinterprets a query before running it against the catalog, rather than matching the raw string as typed. It sits upstream of ranking: ranking decides which matched products appear first, while rewriting decides whether any products get matched at all.
Most zero-result searches aren't caused by a genuinely nonexistent product — they're caused by a literal-match system that couldn't bridge the distance between what a shopper typed and how the catalog is described. Query rewriting is the layer built specifically to close that distance.
How Query Rewriting Recovers Zero-Result Searches
A handful of techniques do most of the work, usually applied in combination rather than one at a time:
- Spelling correction. "winne glases" becomes "wine glasses" before the query ever hits the index — the most common single fix, since typos are a large share of zero-result queries on any storefront.
- Synonym expansion. A query for "trainers" also matches products tagged "sneakers." This is the same mechanism covered in more depth in our guide to ecommerce search synonyms — rewriting is where that synonym map actually gets applied at query time.
- Term dropping. A multi-word query like "waterproof running shoes size 10 blue" that returns nothing gets retried with the least essential word removed, then the next, until it produces results — usually dropping the most specific qualifier first (color, then size) before broader terms.
- Category or attribute broadening. A query that names an out-of-stock or nonexistent exact variant falls back to the parent category or a close attribute match, rather than returning empty.
- Semantic fallback. When rule-based rewriting still comes up empty, some systems fall back to a similarity match between the query's meaning and product descriptions, rather than requiring shared keywords at all. That's the same technique explained in RAG Search Explained and BM25 vs. Semantic Search Relevance.
These aren't mutually exclusive. A single query often gets spelling-corrected, then synonym-expanded, and only falls back to semantic matching if both still fail.
Rule-Based vs. AI-Driven Query Rewriting
Query rewriting splits into two broad approaches, and most production systems use some mix of both:
**Rule-based rewriting** runs on a maintained dictionary: a synonym list, a typo-correction table, manual redirects for known problem queries. It's predictable and easy to audit, but it only covers what someone thought to add — a synonym pair no one entered, or a phrasing no one anticipated, still fails.
**AI-driven rewriting** uses embeddings or a language model to interpret a query's intent rather than matching it against a fixed list, so it can generalize to phrasing nobody explicitly programmed for — "something to serve red wine in" resolving to wine glasses without that exact phrase being in any dictionary. The tradeoff is less predictability: an AI-driven system needs monitoring to catch cases where it broadens a query too far and returns loosely related products instead of no products.
Neither approach fully replaces the other in practice. Rule-based rewriting handles the known, high-frequency cases cheaply and predictably; AI-driven rewriting catches the long tail of descriptive and unanticipated queries that a fixed rule set was never going to cover.
What Query Rewriting Looks Like Across Different Catalogs
The specific failure modes shift by vertical, even though the underlying mechanism is the same:
- Fashion: "trainers" vs. "sneakers," size formats ("UK 8" vs. "US 9"), and color synonyms ("navy" vs. "dark blue") are the recurring gaps.
- Beauty: shoppers search by skin concern or effect ("oily skin," "matte finish") rather than ingredient or product-line names, so rewriting needs to bridge concern language to catalog attributes.
- Electronics: model numbers, abbreviations, and spec shorthand ("27in monitor" vs. "27-inch monitor") are common typo and normalization targets.
- Grocery: brand-vs-generic naming ("soda" vs. a specific brand name) and unit variations ("1L" vs. "1 liter") drive a large share of rewrites.
- Marketplaces: a wide seller vocabulary means the same product gets described a dozen different ways across listings, so synonym and semantic matching carry more of the load than in a single-brand catalog.
- Multilingual storefronts: rewriting has to work across languages a shopper might mix mid-query, not just within one language's spelling variants.
Measuring the Impact of Query Rewriting
The clearest way to see rewriting's effect is in a store's zero-result rate before and after it's applied. In one Semantix case study, Wine House measured 39% of searches returning zero results before adding a recovery layer built on these techniques; 26.5% of the store's search-attributed revenue over the measured period came from queries that recovery caught. In another, Lisa Leonard recovered roughly 10% of its zero-result queries per month, contributing about 1% of incremental revenue — a modest-looking number that compounds because it applies to traffic the store was already paying for.
Figures like these vary by catalog and query mix, so they're illustrative rather than a benchmark to expect out of the box. The more useful exercise is measuring your own zero-result rate first — see Zero-Result Searches: What They Cost and How to Recover Them for how that's typically tracked, or run your numbers through the zero-result calculator to estimate what a high rate is actually costing.
Implementing Query Rewriting: Build vs. Buy
Query rewriting can be built in-house on top of open search infrastructure like Meilisearch or Algolia — both support synonym configuration and typo tolerance natively, with semantic and vector matching available as an added layer. That path makes sense for a team that already owns the surrounding search infrastructure and wants full control over the rewriting logic.
For a Shopify store whose search otherwise works but whose zero-result rate is the specific, measurable problem, a purpose-built recovery layer like Search Saver applies these techniques on top of existing search without a platform migration. See Shopify Search: What's Built In, What's Missing, and How to Fix It for what Shopify's native search already handles versus where rewriting still needs to be added.
The Bottom Line
Query rewriting is the layer that decides whether a search returns something or nothing — spelling correction, synonym expansion, term dropping, category broadening, and semantic fallback, applied in combination rather than as a single fix. Rule-based rewriting handles the predictable, high-frequency cases; AI-driven rewriting extends coverage to descriptive and unanticipated queries a fixed dictionary would miss. Either way, the fastest way to know whether it's worth adding is measuring your own zero-result rate first.
Not sure how much a high zero-result rate is costing your store? Book a demo and we'll help you measure it before recommending a fix.
Frequently asked questions
What is query rewriting in ecommerce search?
Query rewriting is the process of modifying, correcting, or expanding a shopper's search query before matching it against the product catalog — through spelling correction, synonym expansion, term dropping, or semantic fallback — instead of matching the raw typed string literally.
How is query rewriting different from search ranking?
Rewriting happens first and decides whether any products get matched at all; ranking happens after, deciding the order those matched products appear in. A query can be rewritten correctly and still rank poorly, or fail to be rewritten and never reach ranking at all.
Why do zero-result searches happen if the product exists in the catalog?
Most zero-result queries fail because of a mismatch between how a shopper phrases a request and how the catalog describes the product — a typo, an unlisted synonym, or an overly literal multi-word match — not because the product genuinely doesn't exist.
Can query rewriting be added without replacing existing search?
Yes. Rewriting techniques like spelling correction, synonym expansion, and fallback matching can run as a layer on top of an existing search bar and results page, without requiring a new platform or a redesign of the search UI.
Does AI-driven query rewriting replace rule-based synonyms and typo tolerance?
Not typically. Rule-based rewriting handles known, high-frequency cases predictably and cheaply; AI-driven rewriting extends coverage to descriptive or unanticipated phrasing a fixed dictionary wouldn't catch. Most production systems combine both rather than relying on one alone.
How do I know if my store needs better query rewriting?
Measure your zero-result rate first — queries returning empty results despite a catalog that could plausibly match them. A high or rising rate on an otherwise-working search experience is the clearest signal that rewriting, not a full search replacement, is the fix to evaluate.
Semantix Team
Semantix Team