Skip to content

Commit

Permalink
Do not add facet limit unless it is known. (#1989)
Browse files Browse the repository at this point in the history
* Verify search builder not adding facet limit unless it is configured.

This commit updates the code that adds facet limits from user supplied
parameters so that facets are only added if they have been configured
as facet fields.  This is done to allow for multiple faceted searches to
be defined in the same URL while still keeping the facets separate.

* verify constraints component does not render unconfigured facets

Co-authored-by: Benjamin Armintor <armintor@gmail.com>
  • Loading branch information
2 people authored and cbeer committed Jul 31, 2022
1 parent 8abafda commit a537f90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/components/blacklight/constraints_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
it 'renders the query' do
expect(rendered).to have_selector('.constraint-value > .filter-name', text: 'Facet').and(have_selector('.constraint-value > .filter-value', text: 'some value'))
end

context 'that is not configured' do
let(:query_params) { { f: { facet: ['some value'], missing: ['another value'] } } }

it 'renders only the configured constraints' do
expect(rendered).to have_selector('.constraint-value > .filter-name', text: 'Facet').and(have_selector('.constraint-value > .filter-value', text: 'some value'))
expect(rendered).not_to have_selector('.constraint-value > .filter-name', text: 'Missing')
end
end
end

describe '.for_search_history' do
Expand Down
11 changes: 11 additions & 0 deletions spec/models/blacklight/solr/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,17 @@

expect(solr_parameters[:fq]).to be_a_kind_of Array
end

context "facet not defined in config" do
let(:single_facet) { { unknown_facet_field: "foo" } }
let(:user_params) { { f: single_facet } }

it "does not add facet to solr_parameters" do
solr_parameters = Blacklight::Solr::Request.new
subject.add_facet_fq_to_solr(solr_parameters)
expect(solr_parameters[:fq]).to be_blank
end
end
end

describe "#add_solr_fields_to_query" do
Expand Down

0 comments on commit a537f90

Please sign in to comment.