Class: BlacklightRangeLimit::FacetFieldPresenter

Inherits:
Blacklight::FacetFieldPresenter
  • Object
show all
Defined in:
app/presenters/blacklight_range_limit/facet_field_presenter.rb

Instance Method Summary collapse

Instance Method Details

#maxObject



30
31
32
# File 'app/presenters/blacklight_range_limit/facet_field_presenter.rb', line 30

def max
  range_results_endpoint(:max)
end

#minObject



26
27
28
# File 'app/presenters/blacklight_range_limit/facet_field_presenter.rb', line 26

def min
  range_results_endpoint(:min)
end

#missing_facet_itemObject



44
45
46
47
48
49
50
51
# File 'app/presenters/blacklight_range_limit/facet_field_presenter.rb', line 44

def missing_facet_item
  return unless missing.positive?

  Blacklight::Solr::Response::Facets::FacetItem.new(
    value: Blacklight::SearchState::FilterField::MISSING,
    hits: missing
  )
end

#missing_selected?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/presenters/blacklight_range_limit/facet_field_presenter.rb', line 53

def missing_selected?
  selected_range == Blacklight::SearchState::FilterField::MISSING
end

#paginatorObject



22
23
24
# File 'app/presenters/blacklight_range_limit/facet_field_presenter.rb', line 22

def paginator
  nil
end

#range_configObject



57
58
59
# File 'app/presenters/blacklight_range_limit/facet_field_presenter.rb', line 57

def range_config
  @facet_field.range_config
end

#range_queriesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/presenters/blacklight_range_limit/facet_field_presenter.rb', line 8

def range_queries
  return [] unless response.dig('facet_counts', 'facet_queries')

  range_regex = /#{facet_field.field}: *\[ *(-?\d+) *TO *(-?\d+) *\]/

  array = response.dig('facet_counts', 'facet_queries').map do |query, count|
    if (match = range_regex.match(query))
      Blacklight::Solr::Response::Facets::FacetItem.new(value: match[1].to_i..match[2].to_i, hits: count)
    end
  end

  array.compact.sort_by { |item| item.value.first }
end

#selected_rangeObject



34
35
36
# File 'app/presenters/blacklight_range_limit/facet_field_presenter.rb', line 34

def selected_range
  search_state.filter(key).values.first
end

#selected_range_facet_itemObject



38
39
40
41
42
# File 'app/presenters/blacklight_range_limit/facet_field_presenter.rb', line 38

def selected_range_facet_item
  return unless selected_range

  Blacklight::Solr::Response::Facets::FacetItem.new(value: selected_range, hits: response.total)
end