2012-10-09 15:09:46 -04:00
|
|
|
class SearchContext
|
|
|
|
attr_accessor :project_ids, :params
|
|
|
|
|
|
|
|
def initialize(project_ids, params)
|
|
|
|
@project_ids, @params = project_ids, params.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
query = params[:search]
|
|
|
|
|
|
|
|
return result unless query.present?
|
|
|
|
|
2013-04-14 13:07:11 -04:00
|
|
|
projects = Project.where(id: project_ids)
|
2013-08-07 15:51:36 -04:00
|
|
|
result[:projects] = projects.search(query).limit(20)
|
2013-05-09 04:27:14 -04:00
|
|
|
|
|
|
|
# Search inside singe project
|
2013-05-14 13:11:48 -04:00
|
|
|
project = projects.first if projects.length == 1
|
2013-05-09 04:27:14 -04:00
|
|
|
|
|
|
|
if params[:search_code].present?
|
2013-05-14 13:25:16 -04:00
|
|
|
result[:blobs] = project.repository.search_files(query, params[:repository_ref]) unless project.empty_repo?
|
2013-05-09 04:27:14 -04:00
|
|
|
else
|
2013-08-15 04:54:16 -04:00
|
|
|
result[:merge_requests] = MergeRequest.in_projects(project_ids).search(query).order('updated_at DESC').limit(20)
|
|
|
|
result[:issues] = Issue.where(project_id: project_ids).search(query).order('updated_at DESC').limit(20)
|
2013-05-09 04:27:14 -04:00
|
|
|
result[:wiki_pages] = []
|
2013-04-14 13:07:11 -04:00
|
|
|
end
|
2012-10-09 15:09:46 -04:00
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def result
|
|
|
|
@result ||= {
|
|
|
|
projects: [],
|
|
|
|
merge_requests: [],
|
2012-10-16 15:05:11 -04:00
|
|
|
issues: [],
|
2013-04-14 13:07:11 -04:00
|
|
|
wiki_pages: [],
|
2013-05-09 04:27:14 -04:00
|
|
|
blobs: []
|
2012-10-09 15:09:46 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|