Module: BlacklightFacetExtras::Hierarchy::ControllerExtension
- Defined in:
- lib/blacklight_facet_extras/hierarchy/controller_extension.rb
Overview
Meant to be applied on top of a controller that implements Blacklight::SolrHelper. Will inject hierarchy limiting behaviors to solr parameters creation.
Class Method Summary collapse
Instance Method Summary collapse
- #add_hierarchy_facets_to_solr(solr_parameters, user_parameters) ⇒ Object
- #blacklight_hierarchy_config ⇒ Object
- #facet_hierarchy_config(solr_field) ⇒ Object
Class Method Details
.included(some_class) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/blacklight_facet_extras/hierarchy/controller_extension.rb', line 5 def self.included(some_class) some_class.send :include,BlacklightFacetExtras::ControllerExtension some_class.helper_method :facet_hierarchy_config some_class.helper_method :blacklight_hierarchy_config some_class.solr_search_params_logic << :add_hierarchy_facets_to_solr some_class.helper BlacklightFacetExtras::Hierarchy::ViewHelperExtension end |
Instance Method Details
#add_hierarchy_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 |
# File 'lib/blacklight_facet_extras/hierarchy/controller_extension.rb', line 12 def add_hierarchy_facets_to_solr(solr_parameters, user_parameters) blacklight_hierarchy_config.each do |k, config| fq = (solr_parameters[:fq] || []).select { |x| x.starts_with? "{!raw f=#{k}}" }.first.to_s value = fq.gsub("{!raw f=#{k}}", "") solr_parameters[:fq] ||= [] solr_parameters[:fq].delete(fq) if value.blank? solr_parameters[:"f.#{k}.facet.prefix"] ||= "1/" else solr_parameters[:fq] << "{!raw f=#{k}}#{value.count("/") + 1}/#{value}" solr_parameters[:"f.#{k}.facet.prefix"] ||= "#{value.count("/") + 2}/#{value}/" end end solr_parameters end |
#blacklight_hierarchy_config ⇒ Object
37 38 39 |
# File 'lib/blacklight_facet_extras/hierarchy/controller_extension.rb', line 37 def blacklight_hierarchy_config Blacklight.config[:facet][:hierarchy] || {} end |
#facet_hierarchy_config(solr_field) ⇒ Object
31 32 33 34 35 |
# File 'lib/blacklight_facet_extras/hierarchy/controller_extension.rb', line 31 def facet_hierarchy_config(solr_field) config = blacklight_hierarchy_config[solr_field] || false config = {} if config == true config end |