Sha256: 9fdb754d3f479fb5d787b3609e7a0be29af06608e8f07491d6bd4686419db227

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

# These are methods that are used at both the view helper and controller layers
# They are only dependent on `blacklight_config` and `@response`
#
module Blacklight
  module Facet

    def facet_paginator field_config, display_facet
      Blacklight::Solr::FacetPaginator.new(display_facet.items, 
        sort: display_facet.sort,
        offset: display_facet.offset,     
        limit: facet_limit_for(field_config.key))
    end

    def facets_from_request(fields = facet_field_names)
      fields.map { |field| facet_by_field_name(field) }.compact
    end

    def facet_field_names
      blacklight_config.facet_fields.keys
    end

    def facet_configuration_for_field(field)
      f = blacklight_config.facet_fields[field]
      f ||= begin
        _, value = blacklight_config.facet_fields.find { |k,v| v.field.to_s == field.to_s }
        value
      end
      f ||= Blacklight::Configuration::FacetField.new(:field => field).normalize!
    end


    # Get a FacetField object from the @response
    def facet_by_field_name field_or_field_name
      case field_or_field_name
      when String, Symbol, Blacklight::Configuration::FacetField
        facet_field = facet_configuration_for_field(field_or_field_name)
        @response.aggregations[facet_field.key]
      else
        # is this really a useful case?
        field_or_field_name
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blacklight-5.13.1 lib/blacklight/facet.rb
blacklight-5.13.0 lib/blacklight/facet.rb
blacklight-5.12.1 lib/blacklight/facet.rb
blacklight-5.12.0 lib/blacklight/facet.rb