Class: Sunspot::Type::DateType

Inherits:
TimeType show all
Defined in:
sunspot/lib/sunspot/type.rb

Overview

The DateType encapsulates dates (without time information). Internally, Solr does not have a date-only type, so this type indexes data using Solr’s DateField type (which is actually date/time), midnight UTC of the indexed date.

Constant Summary

Constants inherited from TimeType

XMLSCHEMA

Instance Method Summary (collapse)

Methods inherited from TimeType

#indexed_name, #to_literal

Methods inherited from AbstractType

#accepts_dynamic?, #accepts_more_like_this?, #to_literal

Instance Method Details

- (Object) cast(string)

:nodoc:



263
264
265
266
# File 'sunspot/lib/sunspot/type.rb', line 263

def cast(string) #:nodoc:
  time = super
  Date.civil(time.year, time.mon, time.mday)
end

- (Object) to_indexed(value)

:nodoc:



250
251
252
253
254
255
256
257
258
259
260
261
# File 'sunspot/lib/sunspot/type.rb', line 250

def to_indexed(value) #:nodoc:
  if value
    time = 
      if %w(year mon mday).all? { |method| value.respond_to?(method) }
        Time.utc(value.year, value.mon, value.mday)
      else
        date = Date.parse(value.to_s)
        Time.utc(date.year, date.mon, date.mday)
      end
    super(time)
  end
end