Class: Search::Scopes

Inherits:
Object
  • Object
show all
Defined in:
lib/search/scopes.rb

Overview

Central registry for search scopes across all search contexts Provides a single source of truth for scope definitions, availability, and validation logic

Constant Summary collapse

SCOPE_DEFINITIONS =

Scope definitions with metadata (CE scopes only) Format: { scope_key => { label:, sort:, availability: } } availability maps context (:global, :group, :project) to supported search types EE scopes are defined in ee/lib/ee/search/scopes.rb

{
  projects: {
    label: -> { _('Projects') },
    sort: 1,
    availability: {
      global: i[advanced basic],
      group: i[advanced basic]
    }
  },
  blobs: {
    label: -> { _('Code') },
    sort: 2,
    availability: {
      global: i[zoekt advanced],
      group: i[zoekt advanced],
      project: i[zoekt advanced basic]
    }
  },
  # sort: 3 is reserved for EE scopes (epics)
  issues: {
    label: -> { _('Issues') },
    sort: 4,
    availability: {
      global: i[advanced basic],
      group: i[advanced basic],
      project: i[advanced basic]
    }
  },
  merge_requests: {
    label: -> { _('Merge requests') },
    sort: 5,
    availability: {
      global: i[advanced basic],
      group: i[advanced basic],
      project: i[advanced basic]
    }
  },
  wiki_blobs: {
    label: -> { _('Wiki') },
    sort: 6,
    availability: {
      global: i[advanced],
      group: i[advanced],
      project: i[advanced basic]
    }
  },
  commits: {
    label: -> { _('Commits') },
    sort: 7,
    availability: {
      global: i[advanced],
      group: i[advanced],
      project: i[advanced basic]
    }
  },
  notes: {
    label: -> { _('Comments') },
    sort: 8,
    availability: {
      global: i[advanced],
      group: i[advanced],
      project: i[advanced basic]
    }
  },
  milestones: {
    label: -> { _('Milestones') },
    sort: 9,
    availability: {
      global: i[advanced basic],
      group: i[advanced basic],
      project: i[advanced basic]
    }
  },
  users: {
    label: -> { _('Users') },
    sort: 10,
    availability: {
      global: i[advanced basic],
      group: i[advanced basic],
      project: i[advanced basic]
    }
  },
  snippet_titles: {
    label: -> { _('Snippets') },
    sort: 11,
    availability: {
      global: i[advanced basic],
      group: i[advanced basic]
    }
  }
}.freeze
GLOBAL_SEARCH_SETTING_MAP =

Map of scopes to their required application setting for global search (CE scopes) EE scopes are added in ee/lib/ee/search/scopes.rb

{
  'issues' => :global_search_issues_enabled?,
  'merge_requests' => :global_search_merge_requests_enabled?,
  'snippet_titles' => :global_search_snippet_titles_enabled?,
  'users' => :global_search_users_enabled?
}.freeze

Class Method Summary collapse

Class Method Details

.all_scope_namesObject

Get all scope names



115
116
117
# File 'lib/search/scopes.rb', line 115

def all_scope_names
  scope_definitions.keys.map(&:to_s)
end

.available_for_context(context:, container: nil, requested_search_type: nil) ⇒ Array<String>

Get scopes available for a specific context (global, group, project)

Parameters:

  • context (Symbol)

    :global, :group, or :project

  • container (Project, Group, nil) (defaults to: nil)

    The container being searched (optional)

  • requested_search_type (String, Symbol) (defaults to: nil)

    User’s requested search type (optional)

Returns:

  • (Array<String>)

    Array of scope names available for the context



124
125
126
127
128
129
130
131
132
133
# File 'lib/search/scopes.rb', line 124

def available_for_context(context:, container: nil, requested_search_type: nil)
  # Normalize invalid search types to nil
  # This allows scope determination to work even with invalid search_type params
  # The actual validation of search_type happens later via search_type_errors
  requested_search_type = normalize_search_type(requested_search_type)

  scope_definitions.select do |scope, definition|
    valid_definition?(scope, definition, context, container, requested_search_type)
  end.keys.map(&:to_s)
end

.scope_definitionsObject

Returns the scope definitions (can be overridden in EE)



136
137
138
# File 'lib/search/scopes.rb', line 136

def scope_definitions
  SCOPE_DEFINITIONS
end