Module: BlacklightFacetExtras::Query::ControllerExtension
- Defined in:
- lib/blacklight_facet_extras/query/controller_extension.rb
Overview
Meant to be applied on top of a controller that implements Blacklight::SolrHelper. Will inject query limiting behaviors to solr parameters creation.
Class Method Summary collapse
Instance Method Summary collapse
- #add_query_facets_to_solr(solr_parameters, user_parameters) ⇒ Object
- #blacklight_query_config ⇒ Object
- #facet_query_config(solr_field) ⇒ Object
Class Method Details
.included(some_class) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/blacklight_facet_extras/query/controller_extension.rb', line 6 def self.included(some_class) some_class.send :include,BlacklightFacetExtras::ControllerExtension some_class.solr_search_params_logic << :add_query_facets_to_solr some_class.helper_method :facet_query_config some_class.helper BlacklightFacetExtras::Query::ViewHelperExtension end |
Instance Method Details
#add_query_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/query/controller_extension.rb', line 12 def add_query_facets_to_solr(solr_parameters, user_parameters) blacklight_query_config.each do |k, config| solr_parameters[:fq].select { |x| x.starts_with?("{!raw f=#{k}}") }.each do |x| v = solr_parameters[:fq].delete x value = v.gsub("{!raw f=#{k}}", "") value = config[value] if config[value] solr_parameters[:fq] << value end if solr_parameters[:fq] solr_parameters[:"facet.field"].select { |x| x == k }.each do |x| solr_parameters[:"facet.field"].delete x end if solr_parameters[:"facet.field"] solr_parameters[:"facet.query"] ||= [] config.each do |label, query| solr_parameters[:"facet.query"] << query end end end |
#blacklight_query_config ⇒ Object
38 39 40 |
# File 'lib/blacklight_facet_extras/query/controller_extension.rb', line 38 def blacklight_query_config Blacklight.config[:facet][:query] || {} end |
#facet_query_config(solr_field) ⇒ Object
32 33 34 35 36 |
# File 'lib/blacklight_facet_extras/query/controller_extension.rb', line 32 def facet_query_config(solr_field) config = blacklight_query_config[solr_field] || false config = {} if config == true config end |