Class: Sunspot::FacetData::FieldFacetData

Inherits:
Abstract
  • Object
show all
Defined in:
lib/sunspot/facet_data.rb

Overview

FieldFacetData encapsulates the data returned by field facets

Direct Known Subclasses

DateFacetData

Instance Attribute Summary

Attributes inherited from Abstract

#field

Instance Method Summary collapse

Methods inherited from Abstract

#cast, #reference, #row_value

Constructor Details

#initialize(facet_values, field) ⇒ FieldFacetData

Returns a new instance of FieldFacetData.



48
49
50
# File 'lib/sunspot/facet_data.rb', line 48

def initialize(facet_values, field)
  @facet_values, @field = facet_values, field
end

Instance Method Details

#nameObject

The name of the field that contains this facet’s values

Returns

Symbol

The field name



58
59
60
# File 'lib/sunspot/facet_data.rb', line 58

def name
  @field.name
end

#rowsObject

The rows returned for this facet.

Returns

Array

Collection of FacetRow objects, in the order returned by Solr



68
69
70
71
72
73
74
75
76
77
# File 'lib/sunspot/facet_data.rb', line 68

def rows
  @rows ||=
    begin
      rows = []
      @facet_values.each_slice(2) do |value, count|
        rows << yield(row_value(value), count)
      end
      rows
    end
end