diff --git a/app/presenters/blacklight_range_limit/filter_field.rb b/app/presenters/blacklight_range_limit/filter_field.rb index b7af2f11..20fccdfb 100644 --- a/app/presenters/blacklight_range_limit/filter_field.rb +++ b/app/presenters/blacklight_range_limit/filter_field.rb @@ -50,17 +50,16 @@ def remove(item) def values(except: []) params = search_state.params param_key = filters_key - return [] unless params.dig(param_key, config.key) - range = if params.dig(param_key, config.key).is_a? Range params.dig(param_key, config.key) - else + elsif params.dig(param_key, config.key).is_a? Hash begins = Array(params.dig(param_key, config.key, :begin)).map(&:presence) ends = Array(params.dig(param_key, config.key, :end)).map(&:presence) begins.zip(ends).map { |b_bound, e_bound| Range.new(b_bound&.to_i, e_bound&.to_i) if b_bound && e_bound }.compact end f = except.include?(:filters) ? [] : Array(range) + f_missing = [] if except.include?(:missing) f_missing ||= [Blacklight::SearchState::FilterField::MISSING] if params.dig(filters_key, "-#{key}")&.any? { |v| v == Blacklight::Engine.config.blacklight.facet_missing_param } diff --git a/spec/presenters/filter_field_spec.rb b/spec/presenters/filter_field_spec.rb index 30ee0661..c5f0f342 100644 --- a/spec/presenters/filter_field_spec.rb +++ b/spec/presenters/filter_field_spec.rb @@ -57,7 +57,7 @@ end end - context 'with missing data' do + context 'with empty data' do let(:param_values) { { range: { some_field: { begin: '', end: '' } } } } describe '#values' do @@ -67,6 +67,17 @@ end end + context 'with missing data' do + let(:param_values) { { range: { '-some_field': ['[* TO *]']} } } + + describe '#values' do + it 'uses the missing special value' do + expect(filter.values).to eq [Blacklight::SearchState::FilterField::MISSING] + end + end + end + + context 'with array-mangled data' do let(:param_values) { { range: { some_field: { begin: { '0' => '2013' }, end: { '0' => '2022' } } } } }