Class: SearchService
- Inherits:
-
Object
- Object
- SearchService
- Includes:
- Gitlab::Allowable, Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/search_service.rb
Constant Summary collapse
- DEFAULT_PER_PAGE =
Gitlab::SearchResults::DEFAULT_PER_PAGE
- MAX_PER_PAGE =
200
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #abuse_detected? ⇒ Boolean
- #abuse_messages ⇒ Object
- #global_search? ⇒ Boolean
- #global_search_enabled_for_scope? ⇒ Boolean
-
#group ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
-
#initialize(current_user, params = {}) ⇒ SearchService
constructor
A new instance of SearchService.
- #level ⇒ Object
-
#project ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
-
#projects ⇒ Object
rubocop: enable CodeReuse/ActiveRecord.
- #search_aggregations ⇒ Object
- #search_highlight ⇒ Object
- #search_objects(preload_method = nil) ⇒ Object
- #search_results ⇒ Object
- #search_type ⇒ Object
- #search_type_errors ⇒ Object
- #show_snippets? ⇒ Boolean
- #valid_request? ⇒ Boolean
Methods included from Gitlab::Allowable
Constructor Details
#initialize(current_user, params = {}) ⇒ SearchService
Returns a new instance of SearchService.
12 13 14 15 |
# File 'app/services/search_service.rb', line 12 def initialize(current_user, params = {}) @current_user = current_user @params = Gitlab::Search::Params.new(params, detect_abuse: true) end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
10 11 12 |
# File 'app/services/search_service.rb', line 10 def params @params end |
Instance Method Details
#abuse_detected? ⇒ Boolean
80 81 82 |
# File 'app/services/search_service.rb', line 80 def abuse_detected? params.abusive? end |
#abuse_messages ⇒ Object
85 86 87 88 89 |
# File 'app/services/search_service.rb', line 85 def return [] unless params.abusive? params.abuse_detection.errors. end |
#global_search? ⇒ Boolean
45 46 47 |
# File 'app/services/search_service.rb', line 45 def global_search? project.blank? && group.blank? end |
#global_search_enabled_for_scope? ⇒ Boolean
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/services/search_service.rb', line 107 def global_search_enabled_for_scope? return false if show_snippets? && Feature.disabled?(:global_search_snippet_titles_tab, current_user, type: :ops) case params[:scope] when 'blobs' Feature.enabled?(:global_search_code_tab, current_user, type: :ops) when 'commits' Feature.enabled?(:global_search_commits_tab, current_user, type: :ops) when 'issues' Feature.enabled?(:global_search_issues_tab, current_user, type: :ops) when 'merge_requests' Feature.enabled?(:global_search_merge_requests_tab, current_user, type: :ops) when 'snippet_titles' Feature.enabled?(:global_search_snippet_titles_tab, current_user, type: :ops) when 'wiki_blobs' Feature.enabled?(:global_search_wiki_tab, current_user, type: :ops) when 'users' Feature.enabled?(:global_search_users_tab, current_user, type: :ops) else true end end |
#group ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
28 29 30 31 32 33 |
# File 'app/services/search_service.rb', line 28 def group return unless params[:group_id].present? && valid_request? the_group = Group.find_by(id: params[:group_id]) can?(current_user, :read_group, the_group) ? the_group : nil end |
#level ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'app/services/search_service.rb', line 96 def level @level ||= if project 'project' elsif group 'group' else 'global' end end |
#project ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
18 19 20 21 22 23 |
# File 'app/services/search_service.rb', line 18 def project return unless params[:project_id].present? && valid_request? the_project = Project.find_by(id: params[:project_id]) can?(current_user, :read_project, the_project) ? the_project : nil end |
#projects ⇒ Object
rubocop: enable CodeReuse/ActiveRecord
37 38 39 |
# File 'app/services/search_service.rb', line 37 def projects # overridden in EE end |
#search_aggregations ⇒ Object
76 77 78 |
# File 'app/services/search_service.rb', line 76 def search_aggregations search_results.aggregations(scope) end |
#search_highlight ⇒ Object
72 73 74 |
# File 'app/services/search_service.rb', line 72 def search_highlight search_results.highlight_map(scope) end |
#search_objects(preload_method = nil) ⇒ Object
66 67 68 69 70 |
# File 'app/services/search_service.rb', line 66 def search_objects(preload_method = nil) @search_objects ||= ( search_results.objects(scope, page: page, per_page: per_page, preload_method: preload_method) ) end |
#search_results ⇒ Object
61 62 63 |
# File 'app/services/search_service.rb', line 61 def search_results abuse_detected? ? ::Search::EmptySearchResults.new : search_service.execute end |
#search_type ⇒ Object
49 50 51 |
# File 'app/services/search_service.rb', line 49 def search_type 'basic' end |
#search_type_errors ⇒ Object
41 42 43 |
# File 'app/services/search_service.rb', line 41 def search_type_errors # overridden in EE end |
#show_snippets? ⇒ Boolean
53 54 55 |
# File 'app/services/search_service.rb', line 53 def show_snippets? params[:snippets] == 'true' end |
#valid_request? ⇒ Boolean
91 92 93 |
# File 'app/services/search_service.rb', line 91 def valid_request? params.valid? end |