Module: BlacklightRangeLimit::ControllerOverride

Extended by:
ActiveSupport::Concern
Defined in:
lib/blacklight_range_limit/controller_override.rb

Constant Summary collapse

RANGE_LIMIT_FIELDS =
[:range_end, :range_field, :range_start].freeze

Instance Method Summary collapse

Instance Method Details

#range_limitObject

Action method of our own! Delivers a partial that’s a display of a single fields range facets. Used when we need a second Solr query to get range facets, after the first found min/max from result set.

Raises:

  • (ActionController::RoutingError)


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
# File 'lib/blacklight_range_limit/controller_override.rb', line 15

def range_limit
  # The builder in this action will need our special range_limit fields, so we
  # must allow them.
  if blacklight_config.search_state_fields
    missing_keys = RANGE_LIMIT_FIELDS - blacklight_config.search_state_fields
    blacklight_config.search_state_fields.concat(missing_keys)
  end

  @facet = blacklight_config.facet_fields[params[:range_field]]
  raise ActionController::RoutingError, 'Not Found' unless @facet&.range

  # We need to swap out the add_range_limit_params search param filter,
  # and instead add in our fetch_specific_range_limit filter,
  # to fetch only the range limit segments for only specific
  # field (with start/end params) mentioned in query params
  # range_field, range_start, and range_end

  @response, _ = search_service.search_results do |search_builder|
    search_builder.except(:add_range_limit_params).append(:fetch_specific_range_limit)
  end

  display_facet = @response.aggregations[@facet.field] || Blacklight::Solr::Response::Facets::FacetField.new(@facet.key, [], response: @response)

  @presenter = (@facet.presenter || BlacklightRangeLimit::FacetFieldPresenter).new(@facet, display_facet, view_context)

  render BlacklightRangeLimit::RangeSegmentsComponent.new(facet_field: @presenter), layout: !request.xhr?
end