LESSON 04 · Relevance policy

Rank the top few

Turn frequency counts into a stable ordering with explicit guardrails.

SYSTEM VIEW

The suggestion path

Diagram view
Top of “cam”—
Stored—
Shown—

Watch counts become a ranked list for “cam”, then see why a list of exactly five can’t survive one blocked term.

  1. The Index builder ranks completed searches by count. With example counts under “cam”, camping’s 10,000 lifetime searches lead camera’s 3,000. Equal scores break alphabetically, so camel and cameo, at 500 each, always come out camel first and the list doesn’t flicker between builds.

    camping
    10,000 lifetime
    camera
    3,000 lifetime
    Tie
    camel = cameo, 500

    What changed

    • Ranked by count
    • camping leads “cam”
    • Ties: camel before cameo
  2. Lifetime counts go stale, so a time-decayed score shrinks older counts. With an example half-life of seven days, camping’s 10,000 searches two weeks ago, and none since, score 2,500. Camera’s 3,000 today score 3,000, so camera now ranks higher.

    Half-life
    7 days
    camping
    10,000 → 2,500
    camera
    3,000 → 3,000

    What changed

    • Older counts shrink with age
    • camping scores 2,500
    • camera leads “cam”
  3. A scheduled job writes the decayed scores into the serving lists; Elasticsearch’s completion suggester, for one, takes a per-entry weight. Here the Index builder stores exactly five candidates for “cam”: one for each visible slot, and none spare.

    Stored
    5 for “cam”
    Slots
    5

    What changed

    • top 5 for “cam” in the Prefix cache
    • Scores written as weights
  4. The Client types “cam”. The Prefix cache returns its five stored candidates, and the Policy filter blocks one that is on the denylist. The visible list has five slots, but the Client gets only four.

    Stored
    5
    Blocked
    1
    Shown
    4 of 5

    What changed

    • 1 term blocked by policy
    • Client gets 4, not 5
  5. Keep more candidates than slots. The Index builder stores the top 20 for “cam”. The Policy filter removes the blocked term from the 20, then takes the first five, so the Client’s list is full again.

    Stored
    20
    Blocked
    1 of 20
    Shown
    5 of 5

    What changed

    • 20 stored for “cam”
    • Filter first, then take 5
    • Client gets all 5
  6. Twenty candidates instead of five quadruple the list storage, so size the spare from how often filters actually remove entries. Public popularity and personal history are different products: personal suggestions need account-aware access and private caching.

    Stored
    20 vs 5
    Storage
    4×

    What changed

    • List storage ×4
    • Size the spare from block rates

Space plays · ← → step · Home resets

THE IDEA

How it works

A baseline ranks normalized completed searches by count, then breaks ties deterministically (for example, alphabetically) so a list does not flicker between equal scores. Lifetime popularity can be stale, so a time-decayed score can favor recent activity by shrinking older counts. With an example half-life of seven days, a count loses half its weight each week. A term with 10,000 searches two weeks ago and none since scores 2,500. A term with 3,000 searches today scores 3,000 and now ranks higher, even though its lifetime count is far lower.

A product catalog may also account for availability or quality, so a sold-out item does not lead the list. Decide whether rankings differ by region and locale before mixing their signals. Popularity also feeds itself, because people tend to choose what they are shown, so early leaders can stay ahead. Elasticsearch’s completion suggester takes a per-entry weight, so a scheduled job can write decayed scores into it.

Keep more internal candidates than displayed slots. If the visible list has five entries and policy blocks one, a cache with exactly five gives only four. Filter a larger ranked candidate set, such as 20, then take five. That quadruples list storage compared with keeping five, so size it from how often filters actually remove entries. Public popularity and personal search history are different products; personal suggestions need account-aware access and private caching.

DECISION POINT

A blocked phrase is first in a cached top-five list. How can the service still show five safe results?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Define ranking signals, time window, context, and tie-breakers.
  • Filter before selecting the final K results.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
ApplyQUESTION 01

Filters block about 1 in 10 top candidates for a locale, sometimes several under one prefix. The list shows five. What should each prefix store?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.