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

:nodoc:



154
155
156
157
# File 'lib/sunspot/type.rb', line 154

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

.indexed_name(name) ⇒ Object

:nodoc:



137
138
139
# File 'lib/sunspot/type.rb', line 137

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

.to_indexed(value) ⇒ Object

:nodoc:



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/sunspot/type.rb', line 141

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