Class: Sunspot::FacetData::DateFacetData

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

Overview

DateFacetData encapsulates facet date for date-range facets.

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

Returns a new instance of DateFacetData.



84
85
86
87
88
# File 'lib/sunspot/facet_data.rb', line 84

def initialize(facet_values, field)
  @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.



101
102
103
# File 'lib/sunspot/facet_data.rb', line 101

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