Class: Sunspot::Facet

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

Overview

The facet class encapsulates the information returned by Solr for a field facet request.

See wiki.apache.org/solr/SolrFacetingOverview for more information on Solr’s faceting capabilities.

Direct Known Subclasses

DateFacet, InstantiatedFacet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(facet_values, field) ⇒ Facet

:nodoc:



14
15
16
# File 'lib/sunspot/facet.rb', line 14

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

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



12
13
14
# File 'lib/sunspot/facet.rb', line 12

def field
  @field
end

Instance Method Details

#field_nameObject

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

Returns

Symbol

The field name



24
25
26
# File 'lib/sunspot/facet.rb', line 24

def field_name
  @field.name
end

#rowsObject

The rows returned for this facet.

Returns

Array

Collection of FacetRow objects, in the order returned by Solr



34
35
36
37
38
39
40
41
42
43
# File 'lib/sunspot/facet.rb', line 34

def rows
  @rows ||=
    begin
      rows = []
      @facet_values.each_slice(2) do |pair|
        rows << new_row(pair)
      end
      rows
    end
end