Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the full response to the facet fields #2555

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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