lib/sunspot/field.rb in sunspot-2.0.0.pre.120925 vs lib/sunspot/field.rb in sunspot-2.0.0.pre.130115
- old
+ new
@@ -10,10 +10,11 @@
#
def initialize(name, type, options = {}) #:nodoc
@name, @type = name.to_sym, type
@stored = !!options.delete(:stored)
@more_like_this = !!options.delete(:more_like_this)
+ @multiple ||= false
set_indexed_name(options)
raise ArgumentError, "Field of type #{type} cannot be used for more_like_this" unless type.accepts_more_like_this? or !@more_like_this
end
# Convert a value to its representation for Solr indexing. This delegates
@@ -32,11 +33,11 @@
# ArgumentError::
# the value is an array, but this field does not allow multiple values
#
def to_indexed(value)
if value.is_a? Array
- if @multiple
+ if multiple?
value.map { |val| to_indexed(val) }
else
raise ArgumentError, "#{name} is not a multiple-value field, so it cannot index values #{value.inspect}"
end
else
@@ -104,10 +105,10 @@
def set_indexed_name(options)
@indexed_name =
if options[:as]
options.delete(:as).to_s
else
- "#{@type.indexed_name(@name).to_s}#{'m' if @multiple }#{'s' if @stored}#{'v' if more_like_this?}"
+ "#{@type.indexed_name(@name).to_s}#{'m' if multiple? }#{'s' if @stored}#{'v' if more_like_this?}"
end
end
end