debian-mirror-gitlab/lib/gitlab/snippet_search_results.rb

50 lines
1 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
module Gitlab
class SnippetSearchResults < SearchResults
2016-04-02 18:10:28 +05:30
include SnippetsHelper
2015-04-26 12:48:37 +05:30
attr_reader :limit_snippet_ids
def initialize(limit_snippet_ids, query)
@limit_snippet_ids = limit_snippet_ids
@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
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
Snippet.where(id: limit_snippet_ids).search(query).order('updated_at DESC')
end
def snippet_blobs
2016-04-02 18:10:28 +05:30
Snippet.where(id: limit_snippet_ids).search_code(query).order('updated_at DESC')
2015-04-26 12:48:37 +05:30
end
def default_scope
'snippet_blobs'
end
end
end