Class: SearchController

Inherits:
ApplicationController show all
Includes:
SearchHelper
Defined in:
app/controllers/search_controller.rb

Instance Method Summary collapse

Methods included from SearchHelper

#search_autocomplete_opts, #search_entries_info

Methods inherited from ApplicationController

#redirect_back_or_default

Methods included from PageLayoutHelper

#blank_container, #container_class, #fluid_layout, #header_title, #nav, #page_card_attributes, #page_card_meta_tags, #page_description, #page_image, #page_title, #sidebar

Methods included from GitlabRoutingHelper

#activity_project_path, #edit_project_path, #edit_project_url, #issue_path, #issue_url, #merge_request_path, #merge_request_url, #milestone_path, #project_builds_path, #project_commits_path, #project_files_path, #project_path, #project_pipelines_path, #project_snippet_url, #project_url, #runner_path, #runners_path, #toggle_subscription_path

Methods included from Gitlab::GonHelper

#add_gon_variables

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Instance Method Details

#autocompleteObject


50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/search_controller.rb', line 50

def autocomplete
  term = params[:term]

  if params[:project_id].present?
    @project = Project.find_by(id: params[:project_id])
    @project = nil unless can?(current_user, :read_project, @project)
  end

  @ref = params[:project_ref] if params[:project_ref].present?

  render json: search_autocomplete_opts(term).to_json
end

#showObject


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/search_controller.rb', line 8

def show
  return if params[:search].nil? || params[:search].blank?

  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?
    @group = Group.find_by(id: params[:group_id])
    @group = nil unless can?(current_user, :read_group, @group)
  end

  @search_term = params[:search]

  @scope = params[:scope]
  @show_snippets = params[:snippets].eql? 'true'

  @search_results =
    if @project
      unless %w(blobs notes issues merge_requests milestones wiki_blobs
                commits).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 milestones).include?(@scope)
        @scope = 'projects'
      end
      Search::GlobalService.new(current_user, params).execute
    end

  @search_objects = @search_results.objects(@scope, params[:page])
end