2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
module Gitlab
|
|
|
|
class SnippetSearchResults < SearchResults
|
2016-04-02 18:10:28 +05:30
|
|
|
include SnippetsHelper
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
attr_reader :limit_snippets
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def initialize(limit_snippets, query)
|
|
|
|
@limit_snippets = limit_snippets
|
2015-04-26 12:48:37 +05:30
|
|
|
@query = query
|
|
|
|
end
|
|
|
|
|
|
|
|
def objects(scope, page = nil)
|
|
|
|
case scope
|
|
|
|
when 'snippet_titles'
|
2016-04-02 18:10:28 +05:30
|
|
|
snippet_titles.page(page).per(per_page)
|
2015-04-26 12:48:37 +05:30
|
|
|
when 'snippet_blobs'
|
2016-04-02 18:10:28 +05:30
|
|
|
snippet_blobs.page(page).per(per_page)
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
2018-03-17 18:26:18 +05:30
|
|
|
super(scope, nil, false)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def snippet_titles_count
|
|
|
|
@snippet_titles_count ||= snippet_titles.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def snippet_blobs_count
|
|
|
|
@snippet_blobs_count ||= snippet_blobs.count
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2015-04-26 12:48:37 +05:30
|
|
|
def snippet_titles
|
2017-08-17 22:00:37 +05:30
|
|
|
limit_snippets.search(query).order('updated_at DESC').includes(:author)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2015-04-26 12:48:37 +05:30
|
|
|
def snippet_blobs
|
2017-08-17 22:00:37 +05:30
|
|
|
limit_snippets.search_code(query).order('updated_at DESC').includes(:author)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
def default_scope
|
|
|
|
'snippet_blobs'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|