module Sunspot::Type

This module contains singleton objects that represent the types that can be indexed and searched using Sunspot. Plugin developers should be able to add new constants to the Type module; as long as they implement the appropriate methods, Sunspot should be able to integrate them (note that this capability is untested at the moment). The required methods are:

indexed_name

Convert a given field name into its form as stored in Solr. This generally means adding a suffix to match a Solr dynamicField definition.

to_indexed

Convert a value of this type into the appropriate Solr string representation.

cast

Convert a Solr string representation of a value into the appropriate Ruby type.

Public Class Methods

for(object) click to toggle source
# File lib/sunspot/type.rb, line 40
def for(object)
  for_class(object.class)
end
for_class(clazz) click to toggle source
# File lib/sunspot/type.rb, line 34
def for_class(clazz)
  if clazz
    ruby_type_map[clazz.name.to_sym] || for_class(clazz.superclass)
  end
end
register(sunspot_type, *classes) click to toggle source
# File lib/sunspot/type.rb, line 28
def register(sunspot_type, *classes)
  classes.each do |clazz|
    ruby_type_map[clazz.name.to_sym] = sunspot_type.instance
  end
end
to_indexed(object) click to toggle source
# File lib/sunspot/type.rb, line 44
def to_indexed(object)
  if type = self.for(object)
    type.to_indexed(object)
  else
    object.to_s
  end
end
to_literal(object) click to toggle source
# File lib/sunspot/type.rb, line 52
def to_literal(object)
  if type = self.for(object)
    type.to_literal(object)
  else
    raise ArgumentError, "Can't use #{object.inspect} as Solr literal: #{object.class} has no registered Solr type"
  end
end

Private Class Methods

ruby_type_map() click to toggle source
# File lib/sunspot/type.rb, line 62
def ruby_type_map
  @ruby_type_map ||= {}
end