2018-10-22 07:00:50 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-08-29 19:22:45 +00:00
|
|
|
module Gitlab
|
|
|
|
class SnippetSearchResults < SearchResults
|
2016-01-22 09:24:38 +00:00
|
|
|
include SnippetsHelper
|
|
|
|
|
2019-09-30 15:08:09 +00:00
|
|
|
attr_reader :current_user
|
2014-08-29 19:22:45 +00:00
|
|
|
|
2019-09-30 15:08:09 +00:00
|
|
|
def initialize(current_user, query)
|
|
|
|
@current_user = current_user
|
2014-08-29 19:22:45 +00:00
|
|
|
@query = query
|
|
|
|
end
|
|
|
|
|
2020-05-20 06:08:06 +00:00
|
|
|
def objects(scope, page: nil, per_page: DEFAULT_PER_PAGE, preload_method: nil)
|
2020-05-07 21:09:26 +00:00
|
|
|
paginated_objects(snippet_titles, page, per_page)
|
2014-08-29 19:22:45 +00:00
|
|
|
end
|
|
|
|
|
2019-07-15 17:59:57 +00:00
|
|
|
def formatted_count(scope)
|
2020-04-29 09:10:04 +00:00
|
|
|
formatted_limited_count(limited_snippet_titles_count)
|
2019-07-15 17:59:57 +00:00
|
|
|
end
|
|
|
|
|
2019-09-30 15:08:09 +00:00
|
|
|
def limited_snippet_titles_count
|
|
|
|
@limited_snippet_titles_count ||= limited_count(snippet_titles)
|
2014-08-29 19:22:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2019-09-30 15:08:09 +00:00
|
|
|
def snippets
|
2019-10-09 15:05:58 +00:00
|
|
|
SnippetsFinder.new(current_user, finder_params)
|
2019-09-30 15:08:09 +00:00
|
|
|
.execute
|
|
|
|
.includes(:author)
|
|
|
|
.reorder(updated_at: :desc)
|
2014-08-29 19:22:45 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2014-08-29 19:22:45 +00:00
|
|
|
|
2019-09-30 15:08:09 +00:00
|
|
|
def snippet_titles
|
|
|
|
snippets.search(query)
|
|
|
|
end
|
|
|
|
|
2020-05-07 21:09:26 +00:00
|
|
|
def paginated_objects(relation, page, per_page)
|
2019-09-30 15:08:09 +00:00
|
|
|
relation.page(page).per(per_page)
|
|
|
|
end
|
2019-10-09 15:05:58 +00:00
|
|
|
|
|
|
|
def finder_params
|
|
|
|
{}
|
|
|
|
end
|
2014-08-29 19:22:45 +00:00
|
|
|
end
|
|
|
|
end
|
2019-10-09 15:05:58 +00:00
|
|
|
|
|
|
|
Gitlab::SnippetSearchResults.prepend_if_ee('::EE::Gitlab::SnippetSearchResults')
|