Skip to content

Commit

Permalink
Merge pull request #3517 from projectblacklight/backports-8.x
Browse files Browse the repository at this point in the history
[8.x] backport some commits
  • Loading branch information
seanaery authored Feb 24, 2025
2 parents cb7a24e + e81bf3c commit f3ec30f
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 12 deletions.
4 changes: 1 addition & 3 deletions app/components/blacklight/document/action_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def url
end
end

def key
@action.key
end
delegate :key, to: :@action
end
end
end
2 changes: 1 addition & 1 deletion app/components/blacklight/facet_field_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
data-target="#<%= html_id %>"
data-bs-target="#<%= html_id %>"
aria-expanded="<%= @facet_field.collapsed? ? 'false' : 'true' %>"
arial-controls="<%= html_id %>"
aria-controls="<%= html_id %>"
>
<%= label %>
</button>
Expand Down
4 changes: 1 addition & 3 deletions app/presenters/blacklight/json_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def initialize(response, blacklight_config)

delegate :facet_field_names, :facet_configuration_for_field, to: :blacklight_config

def documents
@response.documents
end
delegate :documents, to: :@response

# @return [Array<Blacklight::Solr::Response::Facets::FacetField>]
def search_facets
Expand Down
4 changes: 2 additions & 2 deletions lib/blacklight/search_state/filter_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def include?(item)
def permitted_params
if config.pivot
{
filters_key => config.pivot.each_with_object({}) { |key, filter| filter.merge(key => [], "-#{key}" => []) },
inclusive_filters_key => config.pivot.each_with_object({}) { |key, filter| filter.merge(key => []) }
filters_key => config.pivot.each_with_object({}) { |key, filter| filter.merge!(key => [], "-#{key}" => []) },
inclusive_filters_key => config.pivot.each_with_object({}) { |key, filter| filter.merge!(key => []) }
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def export_as_mock
end

it "is empty for empty result sets", :integration do
get :page_links, params: { f: { "format" => 'empty-result-set' }, counter: 1 }
get :page_links, params: { f: { "format" => ['empty-result-set'] }, counter: 1 }
expect(assigns(:page_link_data)).to be_empty
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/features/facets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,11 @@
end
end
end

describe 'facebook-style facet parameters' do
it 'can perform a search' do
visit '/?f[subject_ssim][0]=Iran.+Viza%CC%84rat-i+Kishvar'
expect(page).to have_text 'Naqdī barā-yi tamām-i fuṣūl'
end
end
end
13 changes: 12 additions & 1 deletion spec/lib/blacklight/parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
let(:search_state) { Blacklight::SearchState.new(query_params, blacklight_config) }
let(:blacklight_config) { Blacklight::Configuration.new }

context 'with facebooks badly mangled query parameters' do
context 'with facebook\'s badly mangled query parameters' do
let(:query_params) do
ActionController::Parameters.new(
f: { field: { '0': 'first', '1': 'second' } },
Expand All @@ -67,6 +67,17 @@
it 'normalizes the facets to the expected format' do
expect(params.permit_search_params.to_h.with_indifferent_access).to include f: { field: %w[first second] }, f_inclusive: { field: %w[first second] }
end

context 'when several fields are configured' do
before do
blacklight_config.add_facet_field 'other_field'
blacklight_config.add_facet_field 'some_other_pivot_field', pivot: %w[abc def]
end

it 'normalizes the facets to the expected format' do
expect(params.permit_search_params.to_h.with_indifferent_access).to include f: { field: %w[first second] }, f_inclusive: { field: %w[first second] }
end
end
end

context 'with filter_search_state_fields set to false' do
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/blacklight/search_state/filter_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,22 @@
expect(search_state.filter('some_field').include?(OpenStruct.new(value: '1'))).to be true
end
end

describe '#permitted_params' do
context 'with a pivot facet' do
let(:blacklight_config) do
Blacklight::Configuration.new.configure do |config|
config.add_facet_field 'my_pivot', pivot: %w[format language_ssim]
end
end

it 'marks all the pivot fields as permitted' do
field = described_class.new blacklight_config.facet_fields['my_pivot'], search_state
expect(field.permitted_params).to eq({
f: { "-format" => [], "-language_ssim" => [], "format" => [], "language_ssim" => [] },
f_inclusive: { "format" => [], "language_ssim" => [] }
})
end
end
end
end
2 changes: 1 addition & 1 deletion spec/services/blacklight/search_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
allow(blacklight_config).to receive(:default_solr_params).and_return(qt: 'custom_request_handler')
allow(blacklight_solr).to receive(:send_and_receive) do |path, params|
expect(path).to eq 'select'
expect(params[:params]['facet.field']).to eq ["format", "{!ex=pub_date_ssim_single}pub_date_ssim", "subject_ssim", "language_ssim", "lc_1letter_ssim", "subject_geo_ssim", "subject_era_ssim"]
expect(params[:params]['facet.field']).to contain_exactly "format", "{!ex=pub_date_ssim_single}pub_date_ssim", "subject_ssim", "language_ssim", "lc_1letter_ssim", "subject_geo_ssim", "subject_era_ssim"
expect(params[:params]["facet.query"]).to eq ["pub_date_ssim:[#{5.years.ago.year} TO *]", "pub_date_ssim:[#{10.years.ago.year} TO *]", "pub_date_ssim:[#{25.years.ago.year} TO *]"]
expect(params[:params]).to include('rows' => 10, 'qt' => "custom_request_handler", 'q' => "", "f.subject_ssim.facet.limit" => 21, 'sort' => "score desc, pub_date_si desc, title_si asc")
end.and_return('response' => { 'docs' => [] })
Expand Down

0 comments on commit f3ec30f

Please sign in to comment.