2012-03-15 19:14:39 -04:00
|
|
|
class SearchController < ApplicationController
|
2014-01-18 07:16:46 -05:00
|
|
|
include SearchHelper
|
|
|
|
|
2012-03-15 19:14:39 -04:00
|
|
|
def show
|
2015-01-21 16:06:21 -05:00
|
|
|
return if params[:search].nil? || params[:search].blank?
|
2014-01-19 13:55:59 -05:00
|
|
|
@project = Project.find_by(id: params[:project_id]) if params[:project_id].present?
|
|
|
|
@group = Group.find_by(id: params[:group_id]) if params[:group_id].present?
|
2014-08-27 02:57:50 -04:00
|
|
|
@scope = params[:scope]
|
2014-09-05 13:30:55 -04:00
|
|
|
@show_snippets = params[:snippets].eql? 'true'
|
2014-01-09 05:37:12 -05:00
|
|
|
|
2015-01-21 16:06:21 -05:00
|
|
|
@search_results =
|
|
|
|
if @project
|
|
|
|
return access_denied! unless can?(current_user, :download_code, @project)
|
|
|
|
|
|
|
|
unless %w(blobs notes issues merge_requests wiki_blobs).
|
|
|
|
include?(@scope)
|
|
|
|
@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
|
|
|
|
unless %w(projects issues merge_requests).include?(@scope)
|
|
|
|
@scope = 'projects'
|
|
|
|
end
|
|
|
|
Search::GlobalService.new(current_user, params).execute
|
|
|
|
end
|
2014-08-27 02:57:50 -04:00
|
|
|
@objects = @search_results.objects(@scope, params[:page])
|
2013-10-23 16:27:40 -04:00
|
|
|
end
|
2014-01-18 07:16:46 -05:00
|
|
|
|
|
|
|
def autocomplete
|
|
|
|
term = params[:term]
|
|
|
|
@project = Project.find(params[:project_id]) if params[:project_id].present?
|
|
|
|
@ref = params[:project_ref] if params[:project_ref].present?
|
|
|
|
|
|
|
|
render json: search_autocomplete_opts(term).to_json
|
|
|
|
end
|
2012-03-15 19:14:39 -04:00
|
|
|
end
|