gitlab-org--gitlab-foss/lib/gitlab/snippet_search_results.rb

50 lines
1,014 B
Ruby
Raw Normal View History

module Gitlab
class SnippetSearchResults < SearchResults
2016-01-22 04:24:38 -05:00
include SnippetsHelper
attr_reader :limit_snippets
def initialize(limit_snippets, query)
@limit_snippets = limit_snippets
@query = query
end
def objects(scope, page = nil)
case scope
when 'snippet_titles'
2016-02-05 11:27:12 -05:00
snippet_titles.page(page).per(per_page)
when 'snippet_blobs'
2016-02-05 11:20:29 -05:00
snippet_blobs.page(page).per(per_page)
else
super
end
end
def total_count
@total_count ||= snippet_titles_count + snippet_blobs_count
end
def snippet_titles_count
@snippet_titles_count ||= snippet_titles.count
end
def snippet_blobs_count
@snippet_blobs_count ||= snippet_blobs.count
end
private
def snippet_titles
limit_snippets.search(query).order('updated_at DESC')
end
def snippet_blobs
limit_snippets.search_code(query).order('updated_at DESC')
end
def default_scope
'snippet_blobs'
end
end
end