Class: SearchService
- Inherits:
-
Object
show all
- 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
Class Method Summary
collapse
Instance Method Summary
collapse
#can?, #can_all?, #can_any?
Constructor Details
#initialize(current_user, params = {}) ⇒ SearchService
Returns a new instance of SearchService.
16
17
18
19
|
# File 'app/services/search_service.rb', line 16
def initialize(current_user, params = {})
@current_user = current_user
@params = Gitlab::Search::Params.new(params, detect_abuse: true)
end
|
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
14
15
16
|
# File 'app/services/search_service.rb', line 14
def params
@params
end
|
Class Method Details
.supported_search_types ⇒ Object
10
11
12
|
# File 'app/services/search_service.rb', line 10
def self.supported_search_types
%w[basic]
end
|
Instance Method Details
#abuse_detected? ⇒ Boolean
79
80
81
|
# File 'app/services/search_service.rb', line 79
def abuse_detected?
params.abusive? || pipe_abuse_detector.abusive?
end
|
#abuse_messages ⇒ Object
84
85
86
87
88
|
# File 'app/services/search_service.rb', line 84
def abuse_messages
return [] unless abuse_detected?
params.abuse_detection.errors.full_messages
end
|
#global_search? ⇒ Boolean
40
41
42
|
# File 'app/services/search_service.rb', line 40
def global_search?
project.blank? && group.blank?
end
|
#global_search_enabled_for_scope? ⇒ Boolean
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'app/services/search_service.rb', line 101
def global_search_enabled_for_scope?
return false if show_snippets? && !::Gitlab::CurrentSettings.global_search_snippet_titles_enabled?
case params[:scope]
when 'issues'
::Gitlab::CurrentSettings.global_search_issues_enabled?
when 'merge_requests'
::Gitlab::CurrentSettings.global_search_merge_requests_enabled?
when 'snippet_titles'
::Gitlab::CurrentSettings.global_search_snippet_titles_enabled?
when 'users'
::Gitlab::CurrentSettings.global_search_users_enabled?
else
true
end
end
|
#group ⇒ Object
28
29
30
31
32
33
|
# File 'app/services/search_service.rb', line 28
def group
return unless params[:group_id].present?
the_group = Group.find_by_id(params[:group_id])
can?(current_user, :read_group, the_group) ? the_group : nil
end
|
#level ⇒ Object
90
91
92
93
94
95
96
97
98
99
|
# File 'app/services/search_service.rb', line 90
def level
@level ||=
if project
'project'
elsif group
'group'
else
'global'
end
end
|
#project ⇒ Object
21
22
23
24
25
26
|
# File 'app/services/search_service.rb', line 21
def project
return unless params[:project_id].present?
the_project = Project.find_by_id(params[:project_id])
can?(current_user, :read_project, the_project) ? the_project : nil
end
|
#search_aggregations ⇒ Object
71
72
73
|
# File 'app/services/search_service.rb', line 71
def search_aggregations
search_results.aggregations(scope)
end
|
#search_counts ⇒ Object
75
76
77
|
# File 'app/services/search_service.rb', line 75
def search_counts
search_results.counts(scope)
end
|
#search_highlight ⇒ Object
67
68
69
|
# File 'app/services/search_service.rb', line 67
def search_highlight
search_results.highlight_map(scope)
end
|
#search_objects(preload_method = nil) ⇒ Object
61
62
63
64
65
|
# File 'app/services/search_service.rb', line 61
def search_objects(preload_method = nil)
@search_objects ||= redact_unauthorized_results(
search_results.objects(scope, page: page, per_page: per_page, preload_method: preload_method)
)
end
|
#search_results ⇒ Object
56
57
58
|
# File 'app/services/search_service.rb', line 56
def search_results
abuse_detected? ? ::Search::EmptySearchResults.new : search_service.execute
end
|
#search_type ⇒ Object
44
45
46
|
# File 'app/services/search_service.rb', line 44
def search_type
'basic'
end
|
#search_type_errors ⇒ Object
36
37
38
|
# File 'app/services/search_service.rb', line 36
def search_type_errors
end
|
#show_snippets? ⇒ Boolean
48
49
50
|
# File 'app/services/search_service.rb', line 48
def show_snippets?
params[:snippets] == 'true'
end
|