Skip to content

Apache Lucene open-source search software

Allow field hash to take an array for values

Erik Hatcher5e4dcfa8895d
diff --git a/client/ruby/solrb/lib/solr/document.rb b/client/ruby/solrb/lib/solr/document.rb
index ad2e9102e59..e29450e02ca 100644
--- a/client/ruby/solrb/lib/solr/document.rb
+++ b/client/ruby/solrb/lib/solr/document.rb
@@ -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
diff --git a/client/ruby/solrb/test/unit/document_test.rb b/client/ruby/solrb/test/unit/document_test.rb
index c0cbf881a7b..bf165667d3e 100644
--- a/client/ruby/solrb/test/unit/document_test.rb
+++ b/client/ruby/solrb/test/unit/document_test.rb
@@ -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