Class: Blacklight::Hierarchy::FacetFieldListComponent

Inherits:
Object
  • Object
show all
Defined in:
app/components/blacklight/hierarchy/facet_field_list_component.rb

Constant Summary collapse

DELIMITER =
'_'

Instance Method Summary collapse

Instance Method Details

#field_nameObject



21
22
23
# File 'app/components/blacklight/hierarchy/facet_field_list_component.rb', line 21

def field_name
  @facet_field.facet_field.field
end

#prefixString

then possible hkey values would be ‘wf’, ‘callnum_top’, and ‘exploded_tag’.

the key in the :hierarchy hash is the “prefix” for the solr field with the hierarchy info. the value

in the hash is a list, where the first element is a list of suffixes, and the second element is the delimiter
used to break up the sections of hierarchical data in the solr field being read.  when joined, the prefix and
suffix should form the field name.  so, for example, 'wf_wps', 'wf_wsp', 'wf_swp', 'callnum_top_facet', and
'exploded_tag_ssim' would be the solr fields with blacklight-hierarchy related configuration according to the
hash above.  ':' would be the delimiter used in all of those fields except for 'callnum_top_facet', which would
use '/'.  exploded_tag_ssim might contain values like ['Book', 'Book : Multi-Volume Work'], and callnum_top_facet
might contain values like ['LB', 'LB/2395', 'LB/2395/.C65', 'LB/2395/.C65/1991'].

note: the suffixes (e.g. ‘ssim’ for ‘exploded_tag’ in the above example) can’t have underscores, otherwise things break.

Returns:

  • (String)

    a key to access the rest of the hierarchy tree, as defined in controller config.facet_display declaration. e.g. if you had this in controller:

    config.facet_display = {
      :hierarchy => {
        'wf' => [['wps','wsp','swp'], ':'],
        'callnum_top' => [['facet'], '/'],
        'exploded_tag' => [['ssim'], ':']
     }
    

    }



45
46
47
# File 'app/components/blacklight/hierarchy/facet_field_list_component.rb', line 45

def prefix
  @prefix ||= field_name.gsub("#{DELIMITER}#{field_name.split(/#{DELIMITER}/).last}", '')
end

#treeString

Returns html for the facet tree.

Parameters:

  • as (Blacklight::Configuration::FacetField)

    defined in controller with config.add_facet_field (and with :partial => ‘blacklight/hierarchy/facet_hierarchy’)

Returns:

  • (String)

    html for the facet tree



11
12
13
14
15
16
17
18
19
# File 'app/components/blacklight/hierarchy/facet_field_list_component.rb', line 11

def tree

  @tree ||= begin
    facet_tree_for_prefix = FacetTree.build(prefix: prefix,
                                            facet_display: blacklight_config.facet_display,
                                            facet_field: @facet_field)
    facet_tree_for_prefix ? facet_tree_for_prefix[field_name] : nil
  end
end