Skip to content

Commit

Permalink
Merge pull request #2555 from projectblacklight/facet-full-response
Browse files Browse the repository at this point in the history
Pass the full response to the facet fields
  • Loading branch information
dkinzer committed Nov 24, 2021
2 parents 0cb78bc + 0ff42ee commit 6293071
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Metrics/ModuleLength:
Exclude:
- 'app/controllers/concerns/blacklight/catalog.rb'
- 'lib/blacklight/solr/search_builder_behavior.rb'
- 'lib/blacklight/solr/response/facets.rb'

Metrics/AbcSize:
Exclude:
Expand Down
16 changes: 12 additions & 4 deletions lib/blacklight/solr/response/facets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def data
@options[:data] || {}
end

def response
@options[:response]
end

def index?
sort == 'index'
end
Expand Down Expand Up @@ -181,7 +185,7 @@ def facet_field_aggregations
end

options = facet_field_aggregation_options(facet_field_name)
facet_field = FacetField.new(facet_field_name, items, options)
facet_field = FacetField.new(facet_field_name, items, options.merge(response: self))

if values[nil]
facet_field.missing = items.find(&:missing)
Expand Down Expand Up @@ -214,7 +218,9 @@ def facet_query_aggregations

items = items.sort_by(&:hits).reverse if facet_field.sort && facet_field.sort.to_sym == :count

hash[field_name] = Blacklight::Solr::Response::Facets::FacetField.new field_name, items
facet_field = Blacklight::Solr::Response::Facets::FacetField.new field_name, items, response: response

hash[field_name] = facet_field
end
end

Expand Down Expand Up @@ -245,7 +251,9 @@ def facet_pivot_aggregations

# alias all the possible blacklight config names..
blacklight_config.facet_fields.select { |_k, v| v.pivot && v.pivot.join(",") == field_name }.each_key do |key|
hash[key] = Blacklight::Solr::Response::Facets::FacetField.new key, items
facet_field = Blacklight::Solr::Response::Facets::FacetField.new key, items, response: self

hash[key] = facet_field
end
end
end
Expand Down Expand Up @@ -289,7 +297,7 @@ def json_facet_aggregations
i
end

options = facet_field_aggregation_options(facet_field_name).merge(data: data)
options = facet_field_aggregation_options(facet_field_name).merge(data: data, response: self)
facet_field = FacetField.new(facet_field_name, items, options)

facet_field.missing = Blacklight::Solr::Response::Facets::FacetItem.new(
Expand Down
6 changes: 6 additions & 0 deletions spec/models/blacklight/solr/response/facets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@
expect(subject.aggregations['my_field'].prefix).to be_nil
end
end

describe '#response' do
it 'provides access to the full solr response' do
expect(subject.aggregations['my_field'].response).to eq subject
end
end
end

describe "#merge_facet" do
Expand Down

0 comments on commit 6293071

Please sign in to comment.