Module: Blacklight::Catalog
- Extended by:
- ActiveSupport::Concern, Deprecation
- Includes:
- ActionController::MimeResponds, Facet, Searchable, Pagy::Backend
- Defined in:
- app/controllers/concerns/blacklight/catalog.rb
Constant Summary collapse
- DEFAULT_FACET_LIMIT =
TODO: deprecate this constant with #facet_limit_for
10
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).
Instance Method Details
#action_documents ⇒ Array
Returns first value is a Blacklight::Solr::Response and the second is a list of documents.
155 156 157 158 159 160 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 155 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
162 163 164 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 162 def action_success_redirect_path search_state.url_for_document(blacklight_config.document_model.new(id: params[:id])) end |
#advanced_search ⇒ Object
81 82 83 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 81 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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 110 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 @pagy = Pagy.new( count: @response.total_count, page_param: "facet.page", page: params["facet.page"], limit: 20 ) 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.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 182 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
169 170 171 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 169 def has_search_parameters? params[:search_field].present? || search_state.has_constraints? end |
#index ⇒ Object
get search results from the solr index
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 36 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.", ActiveSupport::Deprecation.new("8.0", "blacklight") ) @pagy = Pagy.new( count: @response.total_count, page: params[:page], limit: params[:per_page] ) 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
138 139 140 141 142 143 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 138 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
86 87 88 89 90 91 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 86 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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 66 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.", ActiveSupport::Deprecation.new("8.0", "blacklight") ) respond_to do |format| format.html { @search_context = setup_next_and_previous_documents } format.json additional_export_formats(@document, format) end end |
#suggest ⇒ Object
145 146 147 148 149 150 151 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 145 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)
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/concerns/blacklight/catalog.rb', line 94 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 |