Sha256: 210d3e2e8455217ecd636e12dcd4bcda99b48a4af24112095ac5e2661c007d66

Contents?: true

Size: 1016 Bytes

Versions: 11

Compression:

Stored size: 1016 Bytes

Contents

require 'enumerator'

module Sunspot
  #
  # The facet class encapsulates the information returned by Solr for a
  # field facet request.
  #
  # See http://wiki.apache.org/solr/SolrFacetingOverview for more information
  # on Solr's faceting capabilities.
  #
  class Facet
    attr_reader :field

    def initialize(facet_values, field) #:nodoc:
      @facet_values, @field = facet_values, field
    end

    # The name of the field that contains this facet's values
    #
    # ==== Returns
    #
    # Symbol:: The field name
    # 
    def field_name
      @field.name
    end

    # The rows returned for this facet.
    #
    # ==== Returns
    #
    # Array:: Collection of FacetRow objects, in the order returned by Solr
    # 
    def rows
      @rows ||=
        begin
          rows = []
          @facet_values.each_slice(2) do |pair|
            rows << new_row(pair)
          end
          rows
        end
    end

    private

    def new_row(pair)
      FacetRow.new(pair, self)
    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
Chrononaut-sunspot-client-0.9.4 lib/sunspot/facet.rb
UnderpantsGnome-sunspot-0.9.1.1 lib/sunspot/facet.rb
kuahyeow-sunspot-0.9.7 lib/sunspot/facet.rb
kuahyeow-sunspot-0.9.8 lib/sunspot/facet.rb
outoftime-sunspot-0.9.0 lib/sunspot/facet.rb
outoftime-sunspot-0.9.1 lib/sunspot/facet.rb
outoftime-sunspot-0.9.2 lib/sunspot/facet.rb
outoftime-sunspot-0.9.3 lib/sunspot/facet.rb
outoftime-sunspot-0.9.4 lib/sunspot/facet.rb
outoftime-sunspot-0.9.5 lib/sunspot/facet.rb
outoftime-sunspot-0.9.6 lib/sunspot/facet.rb