Parent/child: Reduce memory usage in top children query.

Closes #8165
Closes #8160
This commit is contained in:
Erik Wyatt 2014-09-22 13:23:55 +02:00 committed by Martijn van Groningen
parent 0ff61e1d6f
commit 6dac6ecd93
1 changed files with 3 additions and 1 deletions

View File

@ -208,7 +208,9 @@ public class TopChildrenQuery extends Query {
// we found a match, add it and break // we found a match, add it and break
IntObjectOpenHashMap<ParentDoc> readerParentDocs = parentDocsPerReader.get(indexReader.getCoreCacheKey()); IntObjectOpenHashMap<ParentDoc> readerParentDocs = parentDocsPerReader.get(indexReader.getCoreCacheKey());
if (readerParentDocs == null) { if (readerParentDocs == null) {
readerParentDocs = new IntObjectOpenHashMap<>(indexReader.maxDoc()); //The number of docs in the reader and in the query both upper bound the size of parentDocsPerReader
int mapSize = Math.min(indexReader.maxDoc(), context.from() + context.size());
readerParentDocs = new IntObjectOpenHashMap<>(mapSize);
parentDocsPerReader.put(indexReader.getCoreCacheKey(), readerParentDocs); parentDocsPerReader.put(indexReader.getCoreCacheKey(), readerParentDocs);
} }
ParentDoc parentDoc = readerParentDocs.get(parentDocId); ParentDoc parentDoc = readerParentDocs.get(parentDocId);