diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-04-18 16:02:42 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-04-18 16:02:42 +0000 |
commit | bdc0fc7fff015ae8fe8a3fc21caa78b1e7850ded (patch) | |
tree | f8e4f7903c11b25456ce3e0dfe9c3d8c18210304 /app | |
parent | f97b636f3868199ee06d4b9370d77260d389800d (diff) | |
parent | ab529cddac543c2052f7347d22e87f9a6ed04182 (diff) | |
download | gitlab-ce-bdc0fc7fff015ae8fe8a3fc21caa78b1e7850ded.tar.gz |
Merge branch '30615-refactor-global-search' into 'master'
Refactor group search out of global search
Closes #30615
See merge request !10687
Diffstat (limited to 'app')
-rw-r--r-- | app/services/search/global_service.rb | 11 | ||||
-rw-r--r-- | app/services/search/group_service.rb | 18 | ||||
-rw-r--r-- | app/services/search_service.rb | 2 |
3 files changed, 24 insertions, 7 deletions
diff --git a/app/services/search/global_service.rb b/app/services/search/global_service.rb index 8409b592b72..ff188102b62 100644 --- a/app/services/search/global_service.rb +++ b/app/services/search/global_service.rb @@ -7,16 +7,13 @@ module Search end def execute - group = Group.find_by(id: params[:group_id]) if params[:group_id].present? - projects = ProjectsFinder.new(current_user: current_user).execute - - if group - projects = projects.inside_path(group.full_path) - end - Gitlab::SearchResults.new(current_user, projects, params[:search]) end + def projects + @projects ||= ProjectsFinder.new(current_user: current_user).execute + end + def scope @scope ||= begin allowed_scopes = %w[issues merge_requests milestones] diff --git a/app/services/search/group_service.rb b/app/services/search/group_service.rb new file mode 100644 index 00000000000..29478e3251f --- /dev/null +++ b/app/services/search/group_service.rb @@ -0,0 +1,18 @@ +module Search + class GroupService < Search::GlobalService + attr_accessor :group + + def initialize(user, group, params) + super(user, params) + + @group = group + end + + def projects + return Project.none unless group + return @projects if defined? @projects + + @projects = super.inside_path(group.full_path) + end + end +end diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 8d46a8dab3e..22736c71725 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -54,6 +54,8 @@ class SearchService Search::ProjectService.new(project, current_user, params) elsif show_snippets? Search::SnippetService.new(current_user, params) + elsif group + Search::GroupService.new(current_user, group, params) else Search::GlobalService.new(current_user, params) end |