Add fork filter for zoekt backend
What does this MR do and why?
Related to #411833 (closed)
backend code to allow zoekt code search to filter out forks by default.
Parameter include_forked
can be passed in searches to include or exclude forked projects.
Small refactor to search URL parameter parsing (specifically for boolean params)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
no frontend changes
Database
This change only affects group level searches (not project level or global level).
The ruby code to generate the projects query is generated from Search::GlobalService
and has a group filter applied:
I put the explain plan links in comments under the code where they are used
Before
group = Group.find(107)
projects = ProjectsFinder.new(current_user: User.first).execute.preload(:topics, :project_topics, :route).inside_path(group.full_path)
After
group = Group.find(107)
projects_not_forked = ProjectsFinder.new(current_user: User.first).execute.preload(:topics, :project_topics, :route).inside_path(group.full_path).without_order.not_a_fork
projects_not_archived = ProjectsFinder.new(current_user: User.first).execute.preload(:topics, :project_topics, :route).inside_path(group.full_path).without_order.non_archived
How to set up and validate locally
-
enable
search_add_forked_filter_to_zoekt
feature flagecho "Feature.enable(:search_add_forked_filter_to_zoekt)" | gdk rails c
-
for the namespace you setup for zoekt, make sure the namespace has at least one forked project with searchable text. Since i created new projects with the default README, I searched for
"To make it easy for you to get started with GitLab"
(including the double quotes) -
ensure that Zoekt code search is enabled in your user preferences
-
perform 3 group code searches
-
include_forked=true
: http://gdk.test:3000/search?group_id=107&repository_ref=main&scope=blobs&search=%22To+make+it+easy+for+you+to+get+started+with+GitLab%22&include_forked=true- forked results returned
-
include_forked=false
: http://gdk.test:3000/search?group_id=107&repository_ref=main&scope=blobs&search=%22To+make+it+easy+for+you+to+get+started+with+GitLab%22&include_forked=false- forked results not returned
- no param (default): http://gdk.test:3000/search?group_id=107&repository_ref=main&scope=blobs&search=%22To+make+it+easy+for+you+to+get+started+with+GitLab%22
- forked results not returned
-