Class: Spotlight::SearchesController

Inherits:
ApplicationController show all
Includes:
Base, SearchHelper
Defined in:
app/controllers/spotlight/searches_controller.rb

Overview

CRUD actions for curating browse categories (see BrowseController for the end-user read and index actions)

Instance Method Summary collapse

Methods included from SearchHelper

#search_service, #search_service_context

Methods included from Base

#autocomplete_json_response, #autocomplete_json_response_for_document, #blacklight_config, #controller_tracking_method

Methods included from Config

#exhibit_specific_blacklight_config

Methods included from Concerns::ApplicationController

#enabled_in_spotlight_view_type_configuration?, #field_enabled?

Methods included from Controller

#add_breadcrumb, #blacklight_config, #breadcrumbs, #current_exhibit, #current_masthead, #current_masthead=, #current_site, #default_url_options, #exhibit_masthead?, #exhibit_search_action_url, #exhibit_search_facet_path, #resource_masthead?, #search_action_url, #search_facet_path, #search_state, #set_exhibit_locale_scope, #set_locale

Instance Method Details

#autocompleteObject



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

def autocomplete
  search_params = autocomplete_params.merge(search_field: Spotlight::Engine.config.autocomplete_search_field)
  (response, _document_list) = search_service.search_results do |builder|
    builder.with(search_params)
  end

  respond_to do |format|
    format.json do
      render json: { docs: autocomplete_json_response(response.documents) }
    end
  end
end

#createObject



37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/spotlight/searches_controller.rb', line 37

def create
  @search.assign_attributes(search_params.except((:title unless @search.new_record?)))
  @search.query_params = query_params

  if @search.save
    redirect_back fallback_location: fallback_url,
                  notice: t(:'helpers.submit.search.created', model: @search.class.model_name.human.downcase)
  else
    redirect_back fallback_location: fallback_url, alert: @search.errors.full_messages.join('<br>'.html_safe)
  end
end

#destroyObject



70
71
72
73
# File 'app/controllers/spotlight/searches_controller.rb', line 70

def destroy
  @search.destroy
  redirect_to exhibit_searches_path(@search.exhibit), alert: t(:'helpers.submit.search.destroyed', model: @search.class.model_name.human.downcase)
end

#editObject



31
32
33
34
35
# File 'app/controllers/spotlight/searches_controller.rb', line 31

def edit
  @groups = @exhibit.groups
  add_breadcrumb(@search.full_title, edit_exhibit_search_path(@search.exhibit, @search))
  @exhibit = @search.exhibit
end

#indexObject



17
18
19
20
21
22
23
24
25
# File 'app/controllers/spotlight/searches_controller.rb', line 17

def index
  @groups = @exhibit.groups
  respond_to do |format|
    format.html
    format.json do
      render json: @searches.as_json(methods: %i[full_title count thumbnail_image_url]), root: false
    end
  end
end

#showObject



27
28
29
# File 'app/controllers/spotlight/searches_controller.rb', line 27

def show
  redirect_to exhibit_browse_url(@search.exhibit, @search)
end

#updateObject



62
63
64
65
66
67
68
# File 'app/controllers/spotlight/searches_controller.rb', line 62

def update
  if @search.update search_params
    redirect_to exhibit_searches_path(@search.exhibit), notice: t(:'helpers.submit.search.updated', model: @search.class.model_name.human.downcase)
  else
    render action: 'edit'
  end
end

#update_allObject



75
76
77
78
79
80
81
82
# File 'app/controllers/spotlight/searches_controller.rb', line 75

def update_all
  notice = if @exhibit.update batch_search_params
             t(:'helpers.submit.search.batch_updated', model: Spotlight::Search.model_name.human.pluralize)
           else
             t(:'helpers.submit.search.batch_error', model: Spotlight::Search.model_name.human.pluralize.downcase)
           end
  redirect_back fallback_location: fallback_url, notice:
end