Use search service for projects autocomplete

What does this MR do and why?

Replaces the direct database query in projects_autocomplete with SearchService, mirroring the existing users_autocomplete implementation. This fixes timeouts caused by current_user.authorized_projects running expensive PostgreSQL queries for users with many authorized projects.

When Advanced Search (Elasticsearch/OpenSearch) is enabled, SearchService uses it. When disabled, it falls back to PostgreSQL — avoiding the slow authorized_projects query in both cases.

The change is gated behind a gitlab_com_derisk feature flag: search_projects_autocomplete_use_search_service.

Closes #600103 (closed)

How to set up and validate locally

  1. Enable the feature flag for your user in a Rails console:
    Feature.enable(:search_projects_autocomplete_use_search_service, User.find_by(username: 'root'))
  2. Verify SearchService is used and returns results:
    helper = Class.new do
      include SearchHelper
      include Rails.application.routes.url_helpers
      define_method(:current_user) { User.find_by(username: 'root') }
      def default_url_options = { host: 'localhost' }
      public :projects_autocomplete
    end.new
    pp helper.projects_autocomplete('gitlab')
  3. Disable the flag and verify the existing DB path still works:
    Feature.disable(:search_projects_autocomplete_use_search_service)
    pp helper.projects_autocomplete('gitlab')

With Advanced Search enabled: SearchService returns Gitlab::Elastic::SearchResults — queries go to Elasticsearch.

With Advanced Search disabled: SearchService returns Gitlab::SearchResults — queries go to PostgreSQL via full-text search.

Note: Results may differ slightly between flag-on and flag-off because the two paths use different ranking strategies. SearchService uses full-text relevance ranking across all projects; the old path used authorized_projects sorted by recency and star count.

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.

Related to #600103 (closed)

Edited by Madelein van Niekerk

Merge request reports

Loading