diff --git a/lib/blacklight/solr/search_builder_behavior.rb b/lib/blacklight/solr/search_builder_behavior.rb index 1e5f009b5..f8d744d16 100644 --- a/lib/blacklight/solr/search_builder_behavior.rb +++ b/lib/blacklight/solr/search_builder_behavior.rb @@ -342,7 +342,7 @@ def solr_param_quote(val, options = {}) ## # Convert a facet/value pair into a solr fq parameter - # rubocop:disable Metrics/PerceivedComplexity + # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def facet_value_to_fq_string(facet_field, value, use_local_params: true) facet_config = blacklight_config.facet_fields[facet_field] @@ -361,14 +361,16 @@ def facet_value_to_fq_string(facet_field, value, use_local_params: true) end elsif value.is_a?(Range) prefix = "{!#{local_params.join(' ')}}" unless local_params.empty? - "#{prefix}#{solr_field}:[#{value.first} TO #{value.last}]" + start = value.begin || '*' + finish = value.end || '*' + "#{prefix}#{solr_field}:[#{start} TO #{finish}]" elsif value == Blacklight::SearchState::FilterField::MISSING "-#{solr_field}:[* TO *]" else "{!term f=#{solr_field}#{" #{local_params.join(' ')}" unless local_params.empty?}}#{convert_to_term_value(value)}" end end - # rubocop:enable Metrics/PerceivedComplexity + # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def facet_inclusive_value_to_fq_string(facet_field, values) return if values.blank? diff --git a/spec/models/blacklight/solr/search_builder_behavior_spec.rb b/spec/models/blacklight/solr/search_builder_behavior_spec.rb index e3bd368fb..695719255 100644 --- a/spec/models/blacklight/solr/search_builder_behavior_spec.rb +++ b/spec/models/blacklight/solr/search_builder_behavior_spec.rb @@ -575,6 +575,9 @@ it "handles range requests" do expect(subject.send(:facet_value_to_fq_string, "facet_name", 1..5)).to eq "facet_name:[1 TO 5]" + expect(subject.send(:facet_value_to_fq_string, "facet_name", 1..nil)).to eq "facet_name:[1 TO *]" + expect(subject.send(:facet_value_to_fq_string, "facet_name", nil..5)).to eq "facet_name:[* TO 5]" + expect(subject.send(:facet_value_to_fq_string, "facet_name", nil..nil)).to eq "facet_name:[* TO *]" end it "adds tag local parameters" do