2014-09-02 18:07:02 +05:30
|
|
|
class SearchController < ApplicationController
|
2017-08-17 22:00:37 +05:30
|
|
|
skip_before_action :authenticate_user!
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
include SearchHelper
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
layout 'search'
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def show
|
2017-08-17 22:00:37 +05:30
|
|
|
search_service = SearchService.new(current_user, params)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
@project = search_service.project
|
|
|
|
@group = search_service.group
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
return if params[:search].blank?
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
@search_term = params[:search]
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
@scope = search_service.scope
|
|
|
|
@show_snippets = search_service.show_snippets?
|
|
|
|
@search_results = search_service.search_results
|
|
|
|
@search_objects = search_service.search_objects
|
|
|
|
|
|
|
|
check_single_commit_result
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def autocomplete
|
|
|
|
term = params[:term]
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
if params[:project_id].present?
|
|
|
|
@project = Project.find_by(id: params[:project_id])
|
|
|
|
@project = nil unless can?(current_user, :read_project, @project)
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
@ref = params[:project_ref] if params[:project_ref].present?
|
|
|
|
|
|
|
|
render json: search_autocomplete_opts(term).to_json
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_single_commit_result
|
|
|
|
if @search_results.single_commit_result?
|
|
|
|
only_commit = @search_results.objects('commits').first
|
|
|
|
query = params[:search].strip.downcase
|
|
|
|
found_by_commit_sha = Commit.valid_hash?(query) && only_commit.sha.start_with?(query)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
redirect_to project_commit_path(@project, only_commit) if found_by_commit_sha
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|