Allow field hash to take an array for values

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@496797 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-01-16 17:50:55 +00:00
parent 162dbee7ea
commit 5e4dcfa889
2 changed files with 8 additions and 1 deletions

View File

@ -36,7 +36,9 @@ module Solr
def <<(fields)
case fields
when Hash
fields.each_pair {|k,v| @fields << Solr::Field.new(k => v)}
fields.each_pair do |name,value|
value.each {|v| @fields << Solr::Field.new(name => v)}
end
when Solr::Field
@fields << fields
else

View File

@ -31,6 +31,11 @@ class DocumentTest < Test::Unit::TestCase
assert_equal "<doc><field name='creator'>Erik Hatcher</field><field name='creator'>Otis Gospodnetic</field></doc>", doc.to_xml.to_s
end
def test_repeatable_in_hash
doc = Solr::Document.new({:creator => ['Erik Hatcher', 'Otis Gospodnetic']})
assert_equal "<doc><field name='creator'>Erik Hatcher</field><field name='creator'>Otis Gospodnetic</field></doc>", doc.to_xml.to_s
end
def test_bad_doc
doc = Solr::Document.new
assert_raise(RuntimeError) do