app/helpers/blacklight/hierarchy_helper.rb in blacklight-hierarchy-0.1.1 vs app/helpers/blacklight/hierarchy_helper.rb in blacklight-hierarchy-0.2.0

- old
+ new

@@ -26,27 +26,27 @@ end %{<li class="#{li_class}">#{li.html_safe}#{ul.html_safe}</li>}.html_safe end - # TODO: remove baked in notion of _facet being the suffix of the Solr field name - # # @param [Blacklight::Configuration::FacetField] as defined in controller with config.add_facet_field (and with :partial => 'blacklight/hierarchy/facet_hierarchy') # @return [String] html for the facet tree def render_hierarchy(bl_facet_field, delim='_') field_name = bl_facet_field.field prefix = field_name.gsub("#{delim}#{field_name.split(/#{delim}/).last}", '') + facet_tree_for_prefix = facet_tree(prefix) tree = facet_tree_for_prefix ? facet_tree_for_prefix[field_name] : nil return '' unless tree + tree.keys.sort.collect do |key| render_facet_hierarchy_item(field_name, tree[key], key) end.join("\n").html_safe end def render_qfacet_value(facet_solr_field, item, options ={}) - (link_to_unless(options[:suppress_link], item.value, add_facet_params(facet_solr_field, item.qvalue), :class=>"facet_select") + " " + render_facet_count(item.hits)).html_safe + (link_to_unless(options[:suppress_link], item.value, search_state.add_facet_params(facet_solr_field, item.qvalue), :class=>"facet_select") + " " + render_facet_count(item.hits)).html_safe end # Standard display of a SELECTED facet value, no link, special span with class, and 'remove' button. def render_selected_qfacet_value(facet_solr_field, item) content_tag(:span, render_qfacet_value(facet_solr_field, item, :suppress_link => true), :class => "selected") + " " + @@ -58,14 +58,25 @@ # @param [String] hkey - a key to access the rest of the hierarchy tree, as defined in controller config.facet_display[:hierarchy] declaration. # e.g. if you had this in controller: # config.facet_display = { # :hierarchy => { # 'wf' => [['wps','wsp','swp'], ':'], - # 'callnum' => [['top_facet'], '/'] + # 'callnum_top' => [['facet'], '/'], + # 'exploded_tag' => [['ssim'], ':'] # } # } - # then possible hkey values would be 'wf' and 'callnum' + # 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. def facet_tree(hkey) @facet_tree ||= {} return @facet_tree[hkey] unless @facet_tree[hkey].nil? return @facet_tree[hkey] unless blacklight_config.facet_display[:hierarchy] && blacklight_config.facet_display[:hierarchy][hkey] @facet_tree[hkey] = {} @@ -73,10 +84,10 @@ split_regex = Regexp.new("\s*#{Regexp.escape(facet_config.length >= 2 ? facet_config[1] : ':')}\s*") facet_config.first.each { |key| # TODO: remove baked in notion of underscores being part of the blacklight facet field names facet_field = [hkey,key].compact.join('_') @facet_tree[hkey][facet_field] ||= {} - data = @response.facet_by_field_name(facet_field) + data = @response.aggregations[facet_field] next if data.nil? data.items.each { |facet_item| path = facet_item.value.split(split_regex) loc = @facet_tree[hkey][facet_field]