Class: Sunspot::Search::DateFacet
- Inherits:
-
Object
- Object
- Sunspot::Search::DateFacet
- Defined in:
- sunspot/lib/sunspot/search/date_facet.rb
Instance Method Summary (collapse)
- - (Object) field_name
-
- (DateFacet) initialize(field, search, options)
constructor
A new instance of DateFacet.
- - (Object) rows
Constructor Details
- (DateFacet) initialize(field, search, options)
A new instance of DateFacet
4 5 6 |
# File 'sunspot/lib/sunspot/search/date_facet.rb', line 4 def initialize(field, search, ) @field, @search, @options = field, search, end |
Instance Method Details
- (Object) field_name
8 9 10 |
# File 'sunspot/lib/sunspot/search/date_facet.rb', line 8 def field_name @field.name end |
- (Object) rows
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'sunspot/lib/sunspot/search/date_facet.rb', line 12 def rows @rows ||= begin data = @search.facet_response['facet_dates'][@field.indexed_name] gap = (@options[:time_interval] || 86400).to_i rows = [] data.each_pair do |value, count| if value =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/ start_time = @field.cast(value) end_time = start_time + gap rows << FacetRow.new(start_time..end_time, count, self) end end if @options[:sort] == :count rows.sort! { |lrow, rrow| rrow.count <=> lrow.count } else rows.sort! { |lrow, rrow| lrow.value.first <=> rrow.value.first } end rows end end |