Commit e07b2f527fcaff6f2a998b0a74b0669389fbbbe6

Authored by Dmitriy Zaporozhets
1 parent 02b310df

Fix global search

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
@@ -20,6 +20,7 @@ v 6.7.0 @@ -20,6 +20,7 @@ v 6.7.0
20 - Add retry feature for repository import 20 - Add retry feature for repository import
21 - Reuse the GitLab LDAP connection within each request 21 - Reuse the GitLab LDAP connection within each request
22 - Changed markdown new line behaviour to conform to markdown standards 22 - Changed markdown new line behaviour to conform to markdown standards
  23 + - Fix global search
23 24
24 25
25 v 6.6.2 26 v 6.6.2
app/controllers/search_controller.rb
@@ -7,6 +7,7 @@ class SearchController &lt; ApplicationController @@ -7,6 +7,7 @@ class SearchController &lt; ApplicationController
7 7
8 if @project 8 if @project
9 return access_denied! unless can?(current_user, :download_code, @project) 9 return access_denied! unless can?(current_user, :download_code, @project)
  10 +
10 @search_results = Search::ProjectService.new(@project, current_user, params).execute 11 @search_results = Search::ProjectService.new(@project, current_user, params).execute
11 else 12 else
12 @search_results = Search::GlobalService.new(current_user, params).execute 13 @search_results = Search::GlobalService.new(current_user, params).execute
app/services/search/global_service.rb
@@ -14,9 +14,10 @@ module Search @@ -14,9 +14,10 @@ module Search
14 group = Group.find_by(id: params[:group_id]) if params[:group_id].present? 14 group = Group.find_by(id: params[:group_id]) if params[:group_id].present?
15 projects = Project.accessible_to(current_user) 15 projects = Project.accessible_to(current_user)
16 projects = projects.where(namespace_id: group.id) if group 16 projects = projects.where(namespace_id: group.id) if group
17 - projects = projects.search(query)  
18 project_ids = projects.pluck(:id) 17 project_ids = projects.pluck(:id)
19 18
  19 + projects = projects.search(query)
  20 +
20 result[:projects] = projects.limit(20) 21 result[:projects] = projects.limit(20)
21 result[:merge_requests] = MergeRequest.in_projects(project_ids).search(query).order('updated_at DESC').limit(20) 22 result[:merge_requests] = MergeRequest.in_projects(project_ids).search(query).order('updated_at DESC').limit(20)
22 result[:issues] = Issue.where(project_id: project_ids).search(query).order('updated_at DESC').limit(20) 23 result[:issues] = Issue.where(project_id: project_ids).search(query).order('updated_at DESC').limit(20)