Skip to content

Add fork filter for zoekt backend

Terri Chu requested to merge 411833-backend-for-zoekt-fork-support into master

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

  1. enable and configure zoekt for a namespace

  2. enable search_add_forked_filter_to_zoekt feature flag

    echo "Feature.enable(:search_add_forked_filter_to_zoekt)" | gdk rails c
  3. 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)

  4. ensure that Zoekt code search is enabled in your user preferences

  5. perform 3 group code searches

Edited by Terri Chu

Merge request reports

Loading