public void prepare(PercolateContext context, ParsedDocument parsedDocument) {
IndexReader[] memoryIndices = new IndexReader[parsedDocument.docs().size()];
List<ParseContext.Document> docs = parsedDocument.docs();
int rootDocIndex = docs.size() - 1;
assert rootDocIndex > 0;
MemoryIndex rootDocMemoryIndex = null;
for (int i = 0; i < docs.size(); i++) {
ParseContext.Document d = docs.get(i);
MemoryIndex memoryIndex;
if (rootDocIndex == i) {
// the last doc is always the rootDoc, since that is usually the biggest document it make sense
// to reuse the MemoryIndex it uses
memoryIndex = rootDocMemoryIndex = cache.get();
} else {
memoryIndex = new MemoryIndex(true);
}
memoryIndices[i] = indexDoc(d, parsedDocument.analyzer(), memoryIndex).createSearcher().getIndexReader();
}
MultiReader mReader = new MultiReader(memoryIndices, true);
try {