Loading
Add group query builder and refactoring
What does this MR do and why?
Summary
This change adds Elasticsearch-powered search for GitLab groups, making group searches faster and more relevant. When the feature is enabled, searching for groups will use Elasticsearch, with support for filtering by visibility (public/internal/private), parent group, organization, and archived status, as well as flexible sorting options.
We will add support for basic search (using postgresql) later on in future MRs.
References
Screenshots or screen recordings
| Scope | Advanced | Basic |
|---|---|---|
| Group | ![]() |
![]() |
| Global | ![]() |
![]() |
How to set up and validate locally
Run the following in the rails console:
Feature.enable(:elasticsearch_group_search)
client = Group.__elasticsearch__.client
index_name = Search::Elastic::References::Group.index
groups = Group.limit(10)
Elastic::ProcessInitialBookkeepingService.track!(*groups)
Elastic::ProcessBookkeepingService.new.execute
Elastic::ProcessInitialBookkeepingService.new.execute
user = User.first
query = Search::Elastic::GroupQueryBuilder.new(
query: 'gitlab',
options: { current_user: user }
).build
response = client.search(index: index_name, body: query)
puts "Results: #{response.dig('hits', 'hits').size}"
response.dig('hits', 'hits').each do |hit|
puts " - #{hit['_source']['name']} (ID: #{hit['_source']['id']})"
endOr we can test it via handlers
search_results = Struct.new(:current_user, :query, :filters).new(
user,
'gitlab',
{ order_by: 'updated_at', sort: 'desc', page: 1, per_page: 20 }
)
handler = Search::Handlers::Groups.new(search_results)
results = handler.send(:fetch_results)
puts "Results: #{results.size}"
results.each do |group|
puts " - #{group.name} (ID: #{group.id})"
endMR 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 #607018 (closed)
Edited by Siddharth Dungarwal



