Search empty project repositories with Zoekt without fallback
What does this MR do and why?
Searches a project with an empty repository with Zoekt, returning no results, instead of falling back to advanced or basic search. This is behind the zoekt_search_empty_repo_without_fallback flag, off by default.
Why
A project-level code search only uses Zoekt when a Zoekt node holds a searchable repository for the project (Search::Zoekt::Node.searchable_for_project). An empty repository never gets a Zoekt repository, because there is nothing to index, so these searches fall back to Elasticsearch even when the root namespace is fully on Zoekt. Elasticsearch has no blob documents for an empty repository either, so it returns 0 too. The query is wasted.
Example on GitLab.com: wiki-only projects whose code repository is empty. Their Code tab count (/search/count?scope=blobs) is logged as advanced, while other projects in the same root namespace are searched with Zoekt.
Search::Zoekt::SearchResults#empty_results_preflight_check? already returns empty results, without calling a node, for a project search with no Zoekt node. It also skips the "repository not found" log and the indexing call for empty repositories. This MR lets project search reach that path for empty repositories.
The language sidebar does not use that check. While traversal_id_search is cached as globally available, it sends one aggregation query to the root namespace's replica nodes, filtered to the project, which returns no languages.
This also removes one reason to keep blobs in Advanced Search.
References
- Feature issue: #636136 (code searches still served by Advanced Search)
- Rollout issue: #639156
- Follow-up to !266220 (merged) (queue Zoekt indexing on search fallback)
Screenshots or screen recordings
Not applicable: no UI change beyond the search type used for these projects.
How to set up and validate locally
- Make sure a group is indexed with Zoekt in GDK, and create a project with no repository content in it (do not initialize with a README).
- In the Rails console:
Feature.enable(:zoekt_search_empty_repo_without_fallback) - Search code in that project, for example
http://127.0.0.1:3000/search?scope=blobs&search=foo&project_id=<id>. - The search uses Zoekt (exact code search) and shows no results. With the flag disabled, the same search uses advanced or basic search.
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.