Module: Sunspot::Type::DateType

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.

Class Method Summary collapse

Class Method Details

.cast(string) ⇒ Object



150
151
152
153
# File 'lib/sunspot/type.rb', line 150

def cast(string)
  time = Time.xmlschema(string)
  Date.civil(time.year, time.mon, time.mday)
end

.indexed_name(name) ⇒ Object

:nodoc:



133
134
135
# File 'lib/sunspot/type.rb', line 133

def indexed_name(name) #:nodoc:
  "#{name}_d"
end

.to_indexed(value) ⇒ Object

:nodoc:



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/sunspot/type.rb', line 137

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
    time.utc.xmlschema
  end
end