[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:

  1. Star count boost — uses field_value_factor with ln2p modifier on star_count. The logarithmic scale compresses the range so popular projects rank higher without completely overwhelming exact name matches.
  2. Fork demotion — applies a filter + weight: 0.5 on forked: 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 a field_value_factor function for any numeric field
  • filter_weight_function(filter:, weight:) — builds a filter + weight function 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

How to set up and validate locally

  1. Enable Elasticsearch indexing and ensure projects are indexed
  2. Enable the feature flag:
    Feature.enable(:advanced_search_projects_score_function)
  3. 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.

Edited by Arturo Herrero

Merge request reports

Loading