[Advanced Search] Function score for projects search
What does this MR do and why?
Improves ranking for the Elasticsearch-backed projects search by applying a function_score query that blends two signals into the text relevance score:
- Star count boost — uses
field_value_factorwithln2pmodifier onstar_count. The logarithmic scale compresses the range so popular projects rank higher without completely overwhelming exact name matches. - Fork demotion — applies a
filter+weight: 0.5onforked: true, halving the score of forked projects. Forks are usually less relevant than the original project in search results.
Both functions are multiplied together (score_mode: multiply) and then multiplied with the text relevance score (boost_mode: multiply), so an exact name match still wins over a popular but poorly matched project.
| Signal | Field | Function type | Effect |
|---|---|---|---|
| Star count | star_count |
field_value_factor (ln2p) |
0 stars: ×0.69, 10 stars: ×2.48, 1k stars: ×6.91, 100k stars: ×11.51 |
| Fork demotion | forked |
filter + weight: 0.5 |
Forks: ×0.5, non-forks: ×1.0 |
| Text relevance | — | BM25 (ES default) | Exact name match scores highest |
| Final score | — | boost_mode: multiply |
text_score × star_multiplier × fork_multiplier |
The feature is gated behind the advanced_search_projects_score_function feature flag.
Design
Two reusable helper methods are added to Search::Elastic::Scores:
field_value_function(field:, modifier:)— builds afield_value_factorfunction for any numeric fieldfilter_weight_function(filter:, weight:)— builds afilter+weightfunction for boolean signals
These are composed in ProjectQueryBuilder#build, making it easy to add further signals (e.g. last_activity_at decay, visibility_level boost) in future.
star_count and forked are already indexed and backfilled — no ES migration required.
References
- Rollout issue: #600434 (closed)
How to set up and validate locally
- Enable Elasticsearch indexing and ensure projects are indexed
- Enable the feature flag:
Feature.enable(:advanced_search_projects_score_function) - Search for projects via the global search bar or API and verify that projects with more stars rank higher relative to less popular ones, and that forked projects rank lower than originals
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.