From 7d4801a7e2519f7c5940bf2bbd970cdf3e8bbf92 Mon Sep 17 00:00:00 2001 From: Jamie Johnson Date: Fri, 10 Jun 2016 23:31:15 -0400 Subject: [PATCH] update to support adding documents as a batch to support BlockJoin uses cases --- .../java/uk/co/flax/luwak/DocumentBatch.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/luwak/src/main/java/uk/co/flax/luwak/DocumentBatch.java b/luwak/src/main/java/uk/co/flax/luwak/DocumentBatch.java index 4c64ab2a3..660f89042 100644 --- a/luwak/src/main/java/uk/co/flax/luwak/DocumentBatch.java +++ b/luwak/src/main/java/uk/co/flax/luwak/DocumentBatch.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.*; +import org.apache.lucene.document.Document; import org.apache.lucene.index.*; import org.apache.lucene.index.memory.MemoryIndex; import org.apache.lucene.search.IndexSearcher; @@ -50,7 +51,8 @@ public abstract class DocumentBatch implements Closeable, Iterable documents = new ArrayList<>(); /** @@ -182,9 +184,26 @@ public LeafReader getIndexReader() throws IOException { private LeafReader build(IndexWriter writer) throws IOException { - for (InputDocument doc : documents) { - writer.addDocument(doc.getDocument()); - } + final Iterator it = documents.iterator(); + + Iterable> wrapped = new Iterable>() { + @Override + public Iterator> iterator() { + return new Iterator>() { + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public Iterable next() { + return it.next().getDocument(); + } + }; + } + }; + + writer.addDocuments(wrapped); writer.commit(); LeafReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(directory));