Black Friday: 30% off every plan through November 30. See the prices
SysDesignPrep.com
Study guide

Updated 24 October 2026

Search ranking and relevance

How search results are ordered: retrieval then ranking, text relevance with BM25, business and personal signals, learning to rank, semantic and hybrid search, query understanding, evaluation with NDCG and click metrics, and serving ranking within a latency budget.

Reading is half of it. Now try it in an interview.An AI interviewer asks you to design Yelp, out loud or typed, and scores the answer for your level. Or watch a sample interview first, free with no sign-up to start.
Start an AI mock

Try it yourself, in a playground:Inverted index and search rankingRanking algorithms

Finding documents that match a query is the easy part; ordering them so the best ones come first is what makes search good. A restaurant search that shows a closed, badly rated place at the top, or a rental search that ignores price, loses users. Search questions in interviews (Yelp, Airbnb, product search) expect you to describe how results are ranked, not just indexed.

Two stages: retrieve, then rank

  1. Retrieval (candidate generation): fetch a few hundred or thousand plausible results quickly from an inverted index, a geospatial filter, or a vector index. Cheap scoring only.
  2. Ranking: score those candidates with richer features and a model, then return the top results.
  3. Optionally re-rank the top results with an even more expensive model and apply business rules (diversity, promotions).

This funnel keeps expensive computation on a small set. It mirrors recommendation systems. See recommendation systems.

Text relevance

BM25, the default in Elasticsearch and Lucene, scores a document higher when:

  • query terms appear often in it (with diminishing returns),
  • those terms are rare across all documents (inverse document frequency),
  • the matching field is short (a match in a title counts more than in a long description).

Improve it with field boosts (title over body), phrase and proximity matching, synonyms, and stemming. See how Elasticsearch works.

Text matching misses meaning: "cheap place to eat" should match "affordable diner". Embedding-based retrieval encodes queries and documents as vectors and finds nearest neighbours. Most production systems use hybrid search: combine BM25 and vector results (for example with reciprocal rank fusion), then rank. See vector search and RAG.

Signals beyond text

Signal typeExamples
Qualityratings, review counts, completeness of listing, photo quality
Popularityclicks, bookings, purchases, recent trends
Contextdistance from the user, open now, availability for the dates, price range
Personalpast behaviour, preferences, language
Freshnessrecently updated or created content
Businesssponsored placement (clearly labelled), host or seller quality programs

For local search, distance and "open now" often matter as much as text. See Design Yelp. For rentals, availability and price fit are hard filters plus soft signals. See Design Airbnb.

Learning to rank

Hand-tuned weights stop scaling after a few signals. Learning to rank trains a model (often gradient-boosted trees, or neural networks) on features of (query, document) pairs to predict relevance or the probability of a click or booking. Training labels come from:

  • Human judgements of relevance for sampled queries.
  • User behaviour: clicks, dwell time, conversions, corrected for position bias (people click the top result partly because it is on top).

Features are computed from the index, a feature store and the request. See feature stores and ML serving.

Query understanding

Before retrieval, interpret the query:

  • Spelling correction and normalisation.
  • Intent and entity detection: "pizza near me open now" has a category, a location reference and a filter.
  • Query expansion with synonyms.
  • Autocomplete steering users toward well-formed queries. See tries and autocomplete.

Evaluation

  • Offline: metrics on judged queries, such as NDCG (rewards relevant results near the top), precision at k and recall.
  • Online: click-through rate, conversion rate, time to first click, abandonment, reformulation rate, measured with A/B tests. See feature flags and A/B testing.
  • Watch for feedback loops: popular results get more clicks and stay popular; add exploration and freshness boosts for new items.

Serving within the budget

A search request typically has 100 to 200 ms end to end:

  • Retrieval in tens of milliseconds from in-memory indexes, sharded and replicated.
  • Feature fetches in parallel, batched model scoring of a few hundred candidates.
  • Caching for popular queries (with personalisation applied on top).
  • Fallback to BM25 order if the ranking service is slow.

See tail latency.

In the interview

"Retrieve candidates with BM25 plus a geo filter (and vector search for semantic matches), then rank the top 500 with a learning-to-rank model using text score, distance, rating, popularity and personal features, trained on clicks with position bias correction; evaluate with NDCG offline and conversion in A/B tests."

Checklist

  • Retrieve cheaply, rank expensively, re-rank the top.
  • BM25 with field boosts; hybrid with embeddings for meaning.
  • Quality, popularity, context and personal signals.
  • Learning to rank from judgements and debiased clicks.
  • Query understanding before retrieval.
  • NDCG offline, A/B tests online; exploration against feedback loops.
  • Latency budget with parallel features, caching and fallbacks.

Questions people ask

How does search ranking work?

Search ranking orders the documents that match a query so the best ones come first, usually as a funnel. Retrieval fetches a few hundred or thousand plausible candidates cheaply from an inverted, geospatial or vector index; ranking scores them with richer features and a model; an optional re-rank applies an even more expensive model and business rules such as diversity. The funnel keeps expensive computation on a small set, within a typical end-to-end budget of 100 to 200 ms.

What is BM25?

BM25 is the default text relevance score in Elasticsearch and Lucene. It scores a document higher when query terms appear often in it (with diminishing returns), when those terms are rare across all documents (inverse document frequency), and when the matching field is short, so a title match counts more than a match in a long description. It is improved with field boosts, phrase and proximity matching, synonyms and stemming.

BM25 scores documents by matching the query's terms, while semantic search encodes queries and documents as embedding vectors and finds nearest neighbours, so it captures meaning that text matching misses: "cheap place to eat" should match "affordable diner". Most production systems use hybrid search, combining BM25 and vector results, for example with reciprocal rank fusion, and then ranking the combined candidates.

What is learning to rank?

Learning to rank trains a model, often gradient-boosted trees or a neural network, on features of (query, document) pairs to predict relevance or the probability of a click or booking. It replaces hand-tuned weights, which stop scaling after a few signals. Labels come from human relevance judgements and from user behaviour such as clicks, dwell time and conversions, corrected for position bias, since people click the top result partly because it is on top.

How do you measure search relevance?

Measure it offline on judged queries with metrics such as NDCG, which rewards relevant results near the top, precision at k and recall. Online, A/B tests measure click-through rate, conversion rate, time to first click, abandonment and reformulation rate. Watch for feedback loops, where popular results get more clicks and stay popular, and counter them with exploration and freshness boosts for new items.

What signals are used to rank search results?

Beyond text relevance, ranking uses quality (ratings, review counts, listing completeness), popularity (clicks, bookings, purchases, trends), context (distance, open now, availability, price range), personal signals (past behaviour, preferences, language), freshness, and clearly labelled business signals such as sponsored placement. Which matters most depends on the product: in local search, distance and "open now" often matter as much as text, and in rentals, availability and price fit act as hard filters plus soft signals.