Module: BlacklightFacetExtras::Pivot::ViewHelperExtension

Defined in:
lib/blacklight_facet_extras/pivot/view_helper_extension.rb

Instance Method Summary collapse

Instance Method Details

#render_facet_limit(solr_field) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/blacklight_facet_extras/pivot/view_helper_extension.rb', line 3

def render_facet_limit(solr_field)
  config = facet_pivot_config(solr_field)
  if ( config )
    render(:partial => "catalog/_facet_partials/pivot", :locals=> {:solr_field => solr_field })
  else
    super(solr_field)
  end
end

#render_facet_value(facet_solr_field, item, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/blacklight_facet_extras/pivot/view_helper_extension.rb', line 39

def render_facet_value(facet_solr_field, item, options ={})
  if item.is_a? BlacklightFacetExtras::Pivot::FacetItem
    p = add_facet_params_and_redirect(item.field || facet_solr_field, item.value)

    if item.parent
      p[:f][item.parent.field] ||= []
      p[:f][item.parent.field].push(item.parent.value)
    end

    (link_to_unless(options[:suppress_link], item.display_label || item.value , p, :class=>"facet_select label") + " " + render_facet_count(item.hits)).html_safe
  else
    super(facet_solr_field, item, options ={})
  end
end

#solr_pivot_to_a(solr_field) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/blacklight_facet_extras/pivot/view_helper_extension.rb', line 11

def solr_pivot_to_a(solr_field)
  config = facet_pivot_config(solr_field)
  return RSolr::Ext::Response::Facets::FacetField.new(solr_field, []) unless config and @response and @response["facet_counts"] and @response["facet_counts"]["facet_pivot"] and @response["facet_counts"]["facet_pivot"]

  arr = []
  pivot_field = config.join(",")

  data = @response["facet_counts"]["facet_pivot"][pivot_field]
  return RSolr::Ext::Response::Facets::FacetField.new(solr_field, []) unless data

  data.each do |parent|
    item = BlacklightFacetExtras::Pivot::FacetItem.new(parent['value'], parent['count'], :field => solr_field)

    item.facets ||= []
    parent['pivot'].each do |child|
      label = child['value'].split(" / ").last


      item.facets << BlacklightFacetExtras::Pivot::FacetItem.new(child['value'], child['count'], :display_label => label, :field => child['field'], :parent => item)
    end


    arr << item
  end

  RSolr::Ext::Response::Facets::FacetField.new(solr_field, arr)
end