Class: Sunspot::FacetData::DateFacetData

Inherits:
FieldFacetData show all
Defined in:
lib/sunspot/facet_data.rb

Instance Attribute Summary

Attributes inherited from Abstract

#field

Instance Method Summary collapse

Methods inherited from FieldFacetData

#name

Methods inherited from Abstract

#cast, #reference

Constructor Details

#initialize(facet_values, field) ⇒ DateFacetData

:nodoc:



59
60
61
62
63
# File 'lib/sunspot/facet_data.rb', line 59

def initialize(facet_values, field) #:nodoc:
  @gap = facet_values.delete('gap')[/\+(\d+)SECONDS/,1].to_i
  %w(start end).each { |key| facet_values.delete(key) }
  super(facet_values.to_a.flatten, field)
end

Instance Method Details

#rows(&block) ⇒ Object

Get the rows of this date facet, which are instances of DateFacetRow. The rows will always be sorted in chronological order.

The date facet info comes back from Solr as a hash, so we need to sort it manually. FIXME this currently assumes we want to do a “lexical” sort, but we should support count sort as well, even if it’s not a common use case.



76
77
78
# File 'lib/sunspot/facet_data.rb', line 76

def rows(&block)
  super(&block).sort { |a, b| a.value.first <=> b.value.first }
end