Index: src/test/org/apache/lucene/document/TestDocument.java =================================================================== --- src/test/org/apache/lucene/document/TestDocument.java (revision 962932) +++ src/test/org/apache/lucene/document/TestDocument.java (working copy) @@ -1,5 +1,11 @@ package org.apache.lucene.document; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; + import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; @@ -276,4 +282,31 @@ // expected } } + + public void testAddAll() { + List fields = Arrays.asList( (Fieldable) new Field("field1", new byte[0], Field.Store.YES), + (Fieldable) new Field("field2", "", Field.Store.YES, Field.Index.ANALYZED) ); + Document d = new Document(); + d.addAll(fields); + assertEquals(2, d.getFields().size()); + assertSame(fields.get(0), d.getFieldable(0)); + assertSame(fields.get(1), d.getFieldable(1)); + + d.addAll(fields); + assertEquals(4, d.getFields().size()); + assertSame(fields.get(0), d.getFieldable(2)); + assertSame(fields.get(1), d.getFieldable(3)); + + d.addAll(new HashSet()); + assertEquals(4, d.getFields().size()); + } + + public void testAddAllExceptions() { + try { + (new Document()).addAll(null); + fail("expect a NullPointerException"); + } catch( NullPointerException e ) { + // expected exception + } + } } Index: src/java/org/apache/lucene/index/ParallelReader.java =================================================================== --- src/java/org/apache/lucene/index/ParallelReader.java (revision 962932) +++ src/java/org/apache/lucene/index/ParallelReader.java (working copy) @@ -283,9 +283,7 @@ } if (include) { List fields = reader.document(n, fieldSelector).getFields(); - for (Fieldable field : fields) { - result.add(field); - } + result.addAll(fields); } } return result; Index: src/java/org/apache/lucene/document/Document.java =================================================================== --- src/java/org/apache/lucene/document/Document.java (revision 962932) +++ src/java/org/apache/lucene/document/Document.java (working copy) @@ -88,7 +88,15 @@ public final void add(Fieldable field) { fields.add(field); } - + + /** add all of the provided {@link Fieldable}s to this Document. + * @see #add(Fieldable) + * @param fieldables + */ + public void addAll(final Collection fieldables) { + fields.addAll(fieldables); + } + /** *

Removes field with the specified name from the document. * If multiple fields exist with this name, this method removes the first field that has been added. @@ -138,6 +146,13 @@ return (Field) getFieldable(name); } + /** allow index based access to the Fieldables + * @param i + * @return the ith Fieldable + */ + public final Fieldable getFieldable(final int i) { + return fields.get(i); + } /** Returns a field with the given name if any exist in this document, or * null. If multiple fields exists with this name, this method returns the