2014-08-29 15:22:45 -04:00
|
|
|
module Gitlab
|
|
|
|
class SnippetSearchResults < SearchResults
|
2016-01-22 04:24:38 -05:00
|
|
|
include SnippetsHelper
|
|
|
|
|
2016-03-01 12:01:09 -05:00
|
|
|
attr_reader :limit_snippets
|
2014-08-29 15:22:45 -04:00
|
|
|
|
2016-03-01 12:01:09 -05:00
|
|
|
def initialize(limit_snippets, query)
|
|
|
|
@limit_snippets = limit_snippets
|
2014-08-29 15:22:45 -04:00
|
|
|
@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)
|
2014-08-29 15:22:45 -04:00
|
|
|
when 'snippet_blobs'
|
2016-02-05 11:20:29 -05:00
|
|
|
snippet_blobs.page(page).per(per_page)
|
2014-08-29 15:22:45 -04:00
|
|
|
else
|
|
|
|
super
|
|
|
|
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
|
|
|
|
|
|
|
|
def snippet_titles
|
2017-02-15 05:42:54 -05:00
|
|
|
limit_snippets.search(query).order('updated_at DESC').includes(:author)
|
2014-08-29 15:22:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def snippet_blobs
|
2017-02-15 05:42:54 -05:00
|
|
|
limit_snippets.search_code(query).order('updated_at DESC').includes(:author)
|
2014-08-29 15:22:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def default_scope
|
|
|
|
'snippet_blobs'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|