*** lucene-2.2.0/src/java/org/apache/lucene/index/MultiReader.java 2007-06-16 22:20:35.000000000 -0700 --- src/org/apache/lucene/index/MultiReader.java 2007-10-25 15:00:13.000000000 -0700 *************** *** 105,114 **** --- 105,176 ---- public Document document(int n, FieldSelector fieldSelector) throws CorruptIndexException, IOException { ensureOpen(); int i = readerIndex(n); // find segment num return subReaders[i].document(n - starts[i], fieldSelector); // dispatch to segment reader } + + /* (non-Javadoc) + * @see org.apache.lucene.index.IndexReader#documents(int[], org.apache.lucene.document.FieldSelector) + */ + @Override + public Document[] documents(int[] n, FieldSelector fieldSelector) throws CorruptIndexException, IOException { + + Document[] documents = new Document[n.length]; + + /* + * initialize the counts + */ + int[] counts = new int[subReaders.length]; + for (int x = 0; x < subReaders.length; x++) { + counts[x] = 0; + } + + /* + * figure out the correct reader for each document + */ + int[] readers = new int[n.length]; + for (int x = 0; x < n.length; x++) { + int reader = readerIndex(n[x]); + counts[reader]++; + readers[x] = reader; + } + + /* + * split up the document numbers to go to the correct sub reader + */ + for (int x = 0; x < counts.length; x++) { + + /* + * create an int array we'll send to the sub reader + */ + int position = 0; + int[] request = new int[counts[x]]; + for (int y = 0; y < readers.length; y++) { + if (readers[y] == x) { + request[position] = n[y] - starts[x]; + position++; + } + } + + Document[] results = subReaders[x].documents(request, fieldSelector); + + /* + * put the results into the final document array + */ + position = 0; + for (int y = 0; y < readers.length; y++) { + if (readers[y] == x) { + documents[y] = results[position]; + position++; + } + } + + } + + return documents; + + } public boolean isDeleted(int n) { // Don't call ensureOpen() here (it could affect performance) int i = readerIndex(n); // find segment num return subReaders[i].isDeleted(n - starts[i]); // dispatch to segment reader