diff --git a/app/components/blacklight_range_limit/range_form_component.html.erb b/app/components/blacklight_range_limit/range_form_component.html.erb index 21b960c..db0affb 100644 --- a/app/components/blacklight_range_limit/range_form_component.html.erb +++ b/app/components/blacklight_range_limit/range_form_component.html.erb @@ -5,12 +5,22 @@
<%= label_tag(begin_input_name, t("blacklight.range_limit.range_begin_short"), class: 'text-muted small mb-1') %> - <%= number_field_tag(begin_input_name, begin_value_default, class: "form-control form-control-sm range_begin") %> + <%= number_field_tag(begin_input_name, + begin_value_default, + min: range_config[:min_value], + max: range_config[:max_value], + class: "form-control form-control-sm range_begin") + %>
<%= label_tag(end_input_name, t("blacklight.range_limit.range_end_short"), class: 'text-muted small mb-1') %> - <%= number_field_tag(end_input_name, end_value_default, class: "form-control form-control-sm range_end") %> + <%= number_field_tag(end_input_name, + end_value_default, + min: range_config[:min_value], + max: range_config[:max_value], + class: "form-control form-control-sm range_end") + %>
diff --git a/lib/blacklight_range_limit.rb b/lib/blacklight_range_limit.rb index 7051f0e..0189a4a 100644 --- a/lib/blacklight_range_limit.rb +++ b/lib/blacklight_range_limit.rb @@ -31,7 +31,9 @@ def self.default_range_config chart_segment_border_color: 'rgb(54, 162, 235)', chart_segment_bg_color: 'rgba(54, 162, 235, 0.5)', chart_aspect_ratio: 2, - assumed_boundaries: nil + assumed_boundaries: nil, + min_value: -2_147_483_648, # solr intfield min and max + max_value: 2_147_483_648 }, filter_class: BlacklightRangeLimit::FilterField, presenter: BlacklightRangeLimit::FacetFieldPresenter, diff --git a/lib/blacklight_range_limit/range_limit_builder.rb b/lib/blacklight_range_limit/range_limit_builder.rb index 5c2b6f0..802efa3 100644 --- a/lib/blacklight_range_limit/range_limit_builder.rb +++ b/lib/blacklight_range_limit/range_limit_builder.rb @@ -26,13 +26,7 @@ def add_range_limit_params(solr_params) selected_value = search_state.filter(config.key).values.first - range = if selected_value.is_a? Range - selected_value - elsif range_config[:assumed_boundaries] - Range.new(*range_config[:assumed_boundaries]) - else - nil - end + range = bl_create_selected_range_value(selected_value, config) # If we have both ends of a range add_range_segments_to_solr!(solr_params, field_key, range.begin, range.end) if range && range.count != Float::INFINITY @@ -98,5 +92,30 @@ def facet_value_to_fq_string(facet_field, value, use_local_params: true) end end + # @returns Range or nil + # + # Range created from a range value or from assumed boundaries if present, and clamped between min and max + def bl_create_selected_range_value(selected_value, field_config) + range_config = field_config.range_config + + range = if selected_value.is_a? Range + selected_value + elsif range_config[:assumed_boundaries] + Range.new(*range_config[:assumed_boundaries]) + else + nil + end + + # clamp between config'd min and max + min = range_config[:min_value] + max = range_config[:max_value] + + range = Range.new( + (range.begin.clamp(min, max) if range.begin), + (range.end.clamp(min, max) if range.end), + ) if range + + range + end end end