Course contentsShow
← System Design
Lesson 1761 of 1,91942. Real-World System: Search and TypeaheadFree lesson

Scoring and Ranking Suggestions

Combining popularity, recency, personalization, and other signals to rank typeahead results.

Scoring and Ranking Suggestions

What You'll Learn

You'll learn how to combine multiple signals—popularity, recency, personalization, and more—to rank typeahead suggestions effectively.

The Core Problem

When a user types "sta" into your search box, your trie might return hundreds of matching terms: "starbucks," "star wars," "stanford," "statistics," etc. Simply returning them alphabetically or by first-match is useless. You need a scoring function that blends multiple signals to surface the most relevant suggestions.

Key Ranking Signals

Popularity

Global query frequency is your baseline. If "starbucks" is searched 10M times daily and "star anise" only 1K times, popularity favors Starbucks.

Recency

Trending queries spike temporarily. "Super Bowl 2024" should rank higher during game week, even if its all-time popularity is lower.

Personalization

User context matters: location (rank "starbucks near me" higher in searches from coffee districts), search history (previous queries about movies boost "star wars"), and demographics.

Quality Signals

Click-through rate (CTR) on suggestions, conversion rates, and user satisfaction metrics refine rankings beyond raw volume.

Combining Signals

Your scoring function might look like:

score = w1·popularity + w2·recency_boost + w3·personalization + w4·CTR

The weights (w1, w2, etc.) are tuned via A/B testing or machine learning (learning-to-rank models). You can precompute base scores (popularity + recency) and apply personalization adjustments at query time for speed.

Implementation Strategy

Store scores alongside each node in your trie or in a separate lookup table. When returning top-K suggestions, use the combined score to sort candidates before returning results—typically cached or precomputed for the most common prefixes.

Key Takeaway: Effective typeahead ranking blends multiple signals—popularity, recency, personalization, and quality metrics—through a weighted scoring function that balances relevance with query-time performance constraints.