Module: Blacklight::Catalog
- Extended by:
- ActiveSupport::Concern, Deprecation
- Includes:
- ActionController::MimeResponds, Base, Facet, Searchable
- Included in:
- CatalogController
- Defined in:
- app/controllers/concerns/blacklight/catalog.rb
Constant Summary collapse
- DEFAULT_FACET_LIMIT =
TODO: deprecate this constant with #facet_limit_for
10
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.
-
#facet_limit_for(facet_field) ⇒ Object
Look up facet limit for given 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
-
#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 Facet
#facet_by_field_name, #facet_paginator, #facets_from_request
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.
130 131 132 133 134 135 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 130 def action_documents deprecated_response, @documents = search_service.fetch(Array(params[:id])) raise Blacklight::Exceptions::RecordNotFound if @documents.blank? [deprecated_response, @documents] end |
#action_success_redirect_path ⇒ Object
137 138 139 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 137 def action_success_redirect_path search_state.url_for_document(blacklight_config.document_model.new(id: params[:id])) end |
#advanced_search ⇒ Object
62 63 64 65 66 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 62 def advanced_search empty_service = search_service_class.new(config: blacklight_config, user_params: {}, **search_service_context) (@response, _deprecated_document_list) = empty_service.search_results end |
#facet ⇒ Object
displays values and pagination links for a single facet field
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 93 def facet @facet = blacklight_config.facet_fields[params[:id]] raise ActionController::RoutingError, 'Not Found' unless @facet @response = search_service.facet_field_response(@facet.key) @display_facet = @response.aggregations[@facet.field] @presenter = (@facet.presenter || Blacklight::FacetFieldPresenter).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? # Otherwise draw the facet selector for users who have javascript disabled. end format.json end end |
#facet_limit_for(facet_field) ⇒ Object
Look up facet limit for given facet_field. Will look at config, and if config is 'true' will look up from Solr @response if available. If no limit is available, returns nil. Used from #add_facetting_to_solr to supply f.fieldname.facet.limit values in solr request (no @response available), and used in display (with @response available) to create a facet paginator with the right limit.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 157 def facet_limit_for(facet_field) facet = blacklight_config.facet_fields[facet_field] return if facet.blank? if facet.limit && @response && @response.aggregations[facet.field] limit = @response.aggregations[facet.field].limit if limit.nil? # we didn't get or a set a limit, so infer one. facet.limit if facet.limit != true elsif limit == -1 # limit -1 is solr-speak for unlimited nil else limit.to_i - 1 # we added 1 to find out if we needed to paginate end elsif facet.limit facet.limit == true ? DEFAULT_FACET_LIMIT : facet.limit end end |
#has_search_parameters? ⇒ Boolean
Check if any search parameters have been set
144 145 146 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 144 def has_search_parameters? params[:search_field].present? || search_state.has_constraints? end |
#index ⇒ Object
get search results from the solr index
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 31 def index (@response, deprecated_document_list) = search_service.search_results @document_list = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(deprecated_document_list, 'The @document_list instance variable is deprecated; use @response.documents instead.') respond_to do |format| format.html { store_preferred_view } format.rss { render layout: false } format.atom { render layout: false } format.json do @presenter = Blacklight::JsonPresenter.new(@response, blacklight_config) end additional_response_formats(format) document_export_formats(format) end end |
#opensearch ⇒ Object
method to serve up XML OpenSearch description and JSON autocomplete response
113 114 115 116 117 118 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 113 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
69 70 71 72 73 74 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 69 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
51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 51 def show deprecated_response, @document = search_service.fetch(params[:id]) @response = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(deprecated_response, 'The @response instance variable is deprecated; use @document.response instead.') respond_to do |format| format.html { @search_context = setup_next_and_previous_documents } format.json additional_export_formats(@document, format) end end |
#suggest ⇒ Object
120 121 122 123 124 125 126 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 120 def suggest respond_to do |format| format.json do render json: suggestions_service.suggestions end end end |
#track ⇒ Object
updates the search counter (allows the show view to paginate)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 77 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 |