Module: BlacklightFacetExtras::Range::ControllerExtension
- Defined in:
- lib/blacklight_facet_extras/range/controller_extension.rb
Overview
Meant to be applied on top of a controller that implements Blacklight::SolrHelper. Will inject range limiting behaviors to solr parameters creation.
Class Method Summary collapse
Instance Method Summary collapse
- #add_range_facets_to_solr(solr_parameters, user_parameters) ⇒ Object
- #blacklight_range_config ⇒ Object
- #facet_range_config(solr_field) ⇒ Object
Class Method Details
.included(some_class) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/blacklight_facet_extras/range/controller_extension.rb', line 6 def self.included(some_class) some_class.send :include,BlacklightFacetExtras::ControllerExtension some_class.solr_search_params_logic << :add_range_facets_to_solr some_class.helper_method :facet_range_config some_class.helper BlacklightFacetExtras::Range::ViewHelperExtension end |
Instance Method Details
#add_range_facets_to_solr(solr_parameters, user_parameters) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/blacklight_facet_extras/range/controller_extension.rb', line 12 def add_range_facets_to_solr(solr_parameters, user_parameters) solr_parameters['facet.range.other'] = 'all' blacklight_range_config.each do |k, config| solr_parameters['facet.range'] = k solr_parameters[:fq] ||= [] fq = solr_parameters[:fq].select { |x| x.starts_with?("{!raw f=#{k}}") and x =~ /\[.* TO .*\]/ }.map { |x| solr_parameters[:fq].delete(x) }.map { |x| x.gsub("{!raw f=#{k}}", "") }.map { |x| x.scan(/\[(.*) TO (.*)\]/).first } range_start = fq.map { |x| x.first }.max range_end = fq.map { |x| x.last }.min range_gap = ((range_end.to_i - range_start.to_i) / (facet_limit_for(k) || 10)) if range_start and range_end solr_parameters["f.#{k}.facet.range.start"] = range_start || config[:start] solr_parameters["f.#{k}.facet.range.end"] = range_end || config[:end] solr_parameters["f.#{k}.facet.range.gap"] = range_gap || config[:gap] solr_parameters["f.#{k}.facet.mincount"] = config[:mincount] if config[:mincount] solr_parameters[:fq] << "#{k}:[#{range_start} TO #{range_end}]" if range_start and range_end end end |
#blacklight_range_config ⇒ Object
40 41 42 |
# File 'lib/blacklight_facet_extras/range/controller_extension.rb', line 40 def blacklight_range_config Blacklight.config[:facet][:rangex] || {} end |
#facet_range_config(solr_field) ⇒ Object
34 35 36 37 38 |
# File 'lib/blacklight_facet_extras/range/controller_extension.rb', line 34 def facet_range_config(solr_field) config = blacklight_range_config[solr_field] || false config = {} if config == true config end |