Class: Sunspot::DateFacet

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

Overview

Date facets are retrieved by passing a :time_range key into the DSL::FieldQuery#facet options. They are only available for Date and Time type fields. The #value for date facet rows is a Range object encapsulating the time range covered by the row.

Instance Attribute Summary

Attributes inherited from Facet

#field

Instance Method Summary collapse

Methods inherited from Facet

#field_name

Constructor Details

#initialize(facet_values, field) ⇒ DateFacet

:nodoc:



9
10
11
12
13
# File 'lib/sunspot/date_facet.rb', line 9

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

#rowsObject

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.



26
27
28
# File 'lib/sunspot/date_facet.rb', line 26

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