Class: Sunspot::Type::DateType

Inherits:
TimeType show all
Defined in:
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

TimeType::XMLSCHEMA

Instance Method Summary collapse

Methods inherited from TimeType

#indexed_name, #to_literal

Methods inherited from AbstractType

#accepts_dynamic?, #accepts_more_like_this?, instance, #to_literal

Instance Method Details

#cast(string) ⇒ Object

:nodoc:



261
262
263
264
# File 'lib/sunspot/type.rb', line 261

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

#to_indexed(value) ⇒ Object

:nodoc:



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

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