Module: Sunspot::Type
- Defined in:
- sunspot/lib/sunspot/type.rb
Overview
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. |
Defined Under Namespace
Classes: AbstractType, BooleanType, ClassType, DateType, DoubleType, FloatType, IntegerType, LocationType, LongType, StringType, TextType, TimeType, TrieFloatType, TrieIntegerType, TrieTimeType
Class Method Summary (collapse)
- + (Object) for(object)
- + (Object) for_class(clazz)
- + (Object) register(sunspot_type, *classes)
- + (Object) to_indexed(object)
- + (Object) to_literal(object)
Class Method Details
+ (Object) for(object)
40 41 42 |
# File 'sunspot/lib/sunspot/type.rb', line 40 def for(object) for_class(object.class) end |
+ (Object) for_class(clazz)
34 35 36 37 38 |
# File 'sunspot/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 |
+ (Object) register(sunspot_type, *classes)
28 29 30 31 32 |
# File 'sunspot/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 |
+ (Object) to_indexed(object)
44 45 46 47 48 49 50 |
# File 'sunspot/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 |
+ (Object) to_literal(object)
52 53 54 55 56 57 58 |
# File 'sunspot/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 |