2012-03-15 23:14:39 +00:00
|
|
|
class SearchController < ApplicationController
|
2014-01-18 12:16:46 +00:00
|
|
|
include SearchHelper
|
|
|
|
|
2015-05-01 08:39:11 +00:00
|
|
|
layout 'search'
|
2015-04-30 17:06:18 +00:00
|
|
|
|
2012-03-15 23:14:39 +00:00
|
|
|
def show
|
2015-01-21 21:06:21 +00:00
|
|
|
return if params[:search].nil? || params[:search].blank?
|
2015-04-10 16:39:36 +00:00
|
|
|
|
2015-04-28 09:48:42 +00:00
|
|
|
@search_term = params[:search]
|
|
|
|
|
2015-04-10 16:39:36 +00:00
|
|
|
if params[:project_id].present?
|
|
|
|
@project = Project.find_by(id: params[:project_id])
|
|
|
|
@project = nil unless can?(current_user, :download_code, @project)
|
|
|
|
end
|
|
|
|
|
|
|
|
if params[:group_id].present?
|
2015-04-28 09:48:42 +00:00
|
|
|
@group = Group.find_by(id: params[:group_id])
|
2015-04-10 16:39:36 +00:00
|
|
|
@group = nil unless can?(current_user, :read_group, @group)
|
|
|
|
end
|
2015-04-28 09:48:42 +00:00
|
|
|
|
2014-08-27 06:57:50 +00:00
|
|
|
@scope = params[:scope]
|
2014-09-05 17:30:55 +00:00
|
|
|
@show_snippets = params[:snippets].eql? 'true'
|
2014-01-09 10:37:12 +00:00
|
|
|
|
2015-04-28 09:48:42 +00:00
|
|
|
@search_results =
|
2015-01-21 21:06:21 +00:00
|
|
|
if @project
|
2015-06-14 22:04:20 +00:00
|
|
|
unless %w(blobs notes issues merge_requests milestones wiki_blobs
|
|
|
|
commits).include?(@scope)
|
2015-01-21 21:06:21 +00:00
|
|
|
@scope = 'blobs'
|
|
|
|
end
|
|
|
|
|
|
|
|
Search::ProjectService.new(@project, current_user, params).execute
|
|
|
|
elsif @show_snippets
|
|
|
|
unless %w(snippet_blobs snippet_titles).include?(@scope)
|
|
|
|
@scope = 'snippet_blobs'
|
|
|
|
end
|
|
|
|
|
|
|
|
Search::SnippetService.new(current_user, params).execute
|
|
|
|
else
|
2015-08-13 14:48:21 +00:00
|
|
|
unless %w(projects issues merge_requests milestones).include?(@scope)
|
2015-01-21 21:06:21 +00:00
|
|
|
@scope = 'projects'
|
|
|
|
end
|
|
|
|
Search::GlobalService.new(current_user, params).execute
|
|
|
|
end
|
2015-04-28 09:48:42 +00:00
|
|
|
|
2014-08-27 06:57:50 +00:00
|
|
|
@objects = @search_results.objects(@scope, params[:page])
|
2013-10-23 20:27:40 +00:00
|
|
|
end
|
2014-01-18 12:16:46 +00:00
|
|
|
|
|
|
|
def autocomplete
|
|
|
|
term = params[:term]
|
2015-04-10 16:39:10 +00:00
|
|
|
|
|
|
|
if params[:project_id].present?
|
|
|
|
@project = Project.find_by(id: params[:project_id])
|
|
|
|
@project = nil unless can?(current_user, :read_project, @project)
|
|
|
|
end
|
|
|
|
|
2014-01-18 12:16:46 +00:00
|
|
|
@ref = params[:project_ref] if params[:project_ref].present?
|
|
|
|
|
|
|
|
render json: search_autocomplete_opts(term).to_json
|
|
|
|
end
|
2012-03-15 23:14:39 +00:00
|
|
|
end
|