Module: BlacklightFacetExtras::Tag::ControllerExtension

Defined in:
lib/blacklight_facet_extras/tag/controller_extension.rb

Overview

Meant to be applied on top of a controller that implements Blacklight::SolrHelper. Will inject tag limiting behaviors to solr parameters creation.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(some_class) ⇒ Object



6
7
8
9
10
11
# File 'lib/blacklight_facet_extras/tag/controller_extension.rb', line 6

def self.included(some_class)
  some_class.send :include,BlacklightFacetExtras::ControllerExtension
  some_class.solr_search_params_logic << :add_tag_facets_to_solr
  some_class.helper_method :facet_tag_config
  some_class.helper BlacklightFacetExtras::Tag::ViewHelperExtension
end

Instance Method Details

#add_tag_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/tag/controller_extension.rb', line 12

def add_tag_facets_to_solr(solr_parameters, user_parameters)
  blacklight_tag_config.each do |k, config|


    values = []
    if solr_parameters[:fq]
      solr_parameters[:fq].select { |x| x.starts_with?("{!raw f=#{k}}") }.each do |x|
        values << solr_parameters[:fq].delete(x)
      end 
      solr_parameters[:fq] << "{!tag=#{config[:ex]}} #{values.map { |x| "_query_:\"#{x}\""}.join(" OR ") }" unless values.empty?
    end

    solr_parameters[:"facet.field"].each_with_index.select { |value, index| value == k }.each do |value, index|
      solr_parameters[:"facet.field"][index] = "{!ex=#{config[:ex]}}#{value}"
    end if solr_parameters[:"facet.field"]
  end

  solr_parameters
end

#blacklight_tag_configObject



38
39
40
# File 'lib/blacklight_facet_extras/tag/controller_extension.rb', line 38

def blacklight_tag_config
  Blacklight.config[:facet][:tag] || {}
end

#facet_tag_config(solr_field) ⇒ Object



32
33
34
35
36
# File 'lib/blacklight_facet_extras/tag/controller_extension.rb', line 32

def facet_tag_config(solr_field)
  config = blacklight_tag_config[solr_field] || false
  config = {} if config == true
  config
end