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