Module: Blacklight::Catalog
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActionController::MimeResponds, Configurable, SearchContext, Searchable
- Included in:
- CatalogController
- Defined in:
- app/controllers/concerns/blacklight/catalog.rb
Instance Attribute Summary
Attributes included from Configurable
Instance Method Summary collapse
-
#action_documents ⇒ Array
First value is a Blacklight::Solr::Response and the second is a list of documents.
- #action_success_redirect_path ⇒ Object
- #advanced_search ⇒ Object
-
#facet ⇒ Object
displays values and pagination links for a single facet field.
-
#has_search_parameters? ⇒ Boolean
Check if any search parameters have been set.
-
#index ⇒ Object
get search results from the solr index.
-
#opensearch ⇒ Object
method to serve up XML OpenSearch description and JSON autocomplete response.
-
#raw ⇒ Object
get a single document from the index.
-
#show ⇒ Object
get a single document from the index to add responses for formats other than html or json see Blacklight::Document::Export.
-
#suggest ⇒ Object
Returns the dropdown list for autocomplete.
-
#track ⇒ Object
updates the search counter (allows the show view to paginate).
Methods included from Searchable
#search_service, #search_service_context, #suggestions_service
Methods included from SearchContext
#current_search_session, #page_links, #searches_from_history
Methods included from Configurable
default_configuration, default_configuration=
Instance Method Details
#action_documents ⇒ Array
Returns first value is a Blacklight::Solr::Response and the second is a list of documents.
122 123 124 125 126 127 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 122 def action_documents @documents = search_service.fetch(Array(params[:id])) raise Blacklight::Exceptions::RecordNotFound if @documents.blank? @documents end |
#action_success_redirect_path ⇒ Object
129 130 131 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 129 def action_success_redirect_path search_state.url_for_document(blacklight_config.document_model.new(id: params[:id])) end |
#advanced_search ⇒ Object
49 50 51 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 49 def advanced_search (@response, _deprecated_document_list) = blacklight_advanced_search_form_search_service.search_results end |
#facet ⇒ Object
displays values and pagination links for a single facet field
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 78 def facet # @facet is a Blacklight::Configuration::FacetField @facet = blacklight_config.facet_fields[params[:id]] raise ActionController::RoutingError, 'Not Found' unless @facet @response = if params[:query_fragment].present? search_service.facet_suggest_response(@facet.key, params[:query_fragment]) else search_service.facet_field_response(@facet.key) end # @display_facet is a Blacklight::Solr::Response::Facets::FacetField @display_facet = @response.aggregations[@facet.field] # @presenter is a Blacklight::FacetFieldPresenter @presenter = @facet.presenter.new(@facet, @display_facet, view_context) @pagination = @presenter.paginator respond_to do |format| format.html do # Draw the partial for the "more" facet modal window: return render layout: false if request.xhr? # Only show the facet names and their values: return render 'facet_values', layout: false if params[:only_values] # Otherwise draw the facet selector for users who have javascript disabled. end format.json end end |
#has_search_parameters? ⇒ Boolean
Check if any search parameters have been set
136 137 138 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 136 def has_search_parameters? params[:search_field].present? || search_state.has_constraints? end |
#index ⇒ Object
get search results from the solr index
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 24 def index @response = retrieve_search_results respond_to do |format| format.html { store_preferred_view } format.rss { render layout: false } format.atom { render layout: false } format.json { @presenter = json_presenter(@response) } additional_response_formats(format) document_export_formats(format) end end |
#opensearch ⇒ Object
method to serve up XML OpenSearch description and JSON autocomplete response
107 108 109 110 111 112 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 107 def opensearch respond_to do |format| format.xml { render layout: false } format.json { render json: search_service.opensearch_response } end end |
#raw ⇒ Object
get a single document from the index
54 55 56 57 58 59 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 54 def raw raise(ActionController::RoutingError, 'Not Found') unless blacklight_config.raw_endpoint.enabled @document = search_service.fetch(params[:id]) render json: @document end |
#show ⇒ Object
get a single document from the index to add responses for formats other than html or json see Blacklight::Document::Export
39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 39 def show @document = search_service.fetch(params[:id]) respond_to do |format| format.html { @search_context = setup_next_and_previous_documents } format.json additional_export_formats(@document, format) end end |
#suggest ⇒ Object
Returns the dropdown list for autocomplete
115 116 117 118 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 115 def suggest @suggestions = suggestions_service.suggestions render 'suggest', layout: false end |
#track ⇒ Object
updates the search counter (allows the show view to paginate)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 62 def track search_session['counter'] = params[:counter] search_session['id'] = params[:search_id] search_session['per_page'] = params[:per_page] search_session['document_id'] = params[:document_id] if params[:redirect] && (params[:redirect].starts_with?('/') || params[:redirect] =~ URI::DEFAULT_PARSER.make_regexp) uri = URI.parse(params[:redirect]) path = uri.query ? "#{uri.path}?#{uri.query}" : uri.path redirect_to path, status: :see_other else redirect_to({ action: :show, id: params[:id] }, status: :see_other) end end |