You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by eh...@apache.org on 2007/01/27 18:26:55 UTC

svn commit: r500566 - /lucene/solr/trunk/client/ruby/solrb/lib/solr/request/add_document.rb

Author: ehatcher
Date: Sat Jan 27 09:26:54 2007
New Revision: 500566

URL: http://svn.apache.org/viewvc?view=rev&rev=500566
Log:
SOLR-121: Add support for multiple document adds. (contributed by Coda Hale)


Modified:
    lucene/solr/trunk/client/ruby/solrb/lib/solr/request/add_document.rb

Modified: lucene/solr/trunk/client/ruby/solrb/lib/solr/request/add_document.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solrb/lib/solr/request/add_document.rb?view=diff&rev=500566&r1=500565&r2=500566
==============================================================================
--- lucene/solr/trunk/client/ruby/solrb/lib/solr/request/add_document.rb (original)
+++ lucene/solr/trunk/client/ruby/solrb/lib/solr/request/add_document.rb Sat Jan 27 09:26:54 2007
@@ -26,15 +26,17 @@
       # as a short cut you can pass in a Hash instead:
       #
       #   request = Solr::Request.new :creator => 'Jorge Luis Borges'
+      # 
+      # or an array, to add multiple documents at the same time:
+      # 
+      #   request = Solr::Request::AddDocument.new([doc1, doc2, doc3])
         
       def initialize(doc={})
-        case doc
-        when Hash
-          @doc = Solr::Document.new(doc)
-        when Solr::Document
-          @doc = doc
+        @docs = []
+        if doc.is_a?(Array)
+          doc.each { |d| add_doc(d) }
         else
-          raise "must pass in Solr::Document or Hash"
+          add_doc(doc)
         end
       end
 
@@ -42,9 +44,25 @@
       
       def to_s
         e = REXML::Element.new 'add'
-        e.add_element @doc.to_xml
+        for doc in @docs
+          e.add_element doc.to_xml
+        end
         return e.to_s
       end
+      
+    private
+      
+      def add_doc(doc)
+        case doc
+        when Hash
+          @docs << Solr::Document.new(doc)
+        when Solr::Document
+          @docs << doc
+        else
+          raise "must pass in Solr::Document or Hash"
+        end
+      end
+      
     end
   end
 end