Apache Lucene open-source search software
LUCENE-2837: only populate subSearchers if they will be used
Yonik Seeley8dfb827d0c8d
diff --git a/lucene/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/src/java/org/apache/lucene/search/IndexSearcher.javaindex 4136c0458e8..2fdff34ad13 100644--- a/lucene/src/java/org/apache/lucene/search/IndexSearcher.java+++ b/lucene/src/java/org/apache/lucene/search/IndexSearcher.java@@ -64,9 +64,10 @@ public class IndexSearcher {// in the next releaseprotected final ReaderContext readerContext;protected final AtomicReaderContext[] leafContexts;- protected final IndexSearcher[] subSearchers;-// protected final int[] docStarts;++ // These are only used for multi-threaded searchprivate final ExecutorService executor;+ protected final IndexSearcher[] subSearchers;/** The Similarity implementation used by this searcher. */private Similarity similarity = Similarity.getDefault();@@ -165,12 +166,17 @@ public class IndexSearcher {assert context.leaves() != null : "non-atomic top-level context must have leaves";this.leafContexts = context.leaves();}- subSearchers = new IndexSearcher[this.leafContexts.length];- for (int i = 0; i < subSearchers.length; i++) { // TODO do we need those IS if executor is null?- if (leafContexts[i].reader == context.reader) {- subSearchers[i] = this;- } else {- subSearchers[i] = new IndexSearcher(leafContexts[i].reader.getTopReaderContext()); // we need to get a TL context for sub searchers!++ if (executor == null) {+ subSearchers = null;+ } else {+ subSearchers = new IndexSearcher[this.leafContexts.length];+ for (int i = 0; i < subSearchers.length; i++) {+ if (leafContexts[i].reader == context.reader) {+ subSearchers[i] = this;+ } else {+ subSearchers[i] = new IndexSearcher(leafContexts[i].reader.getTopReaderContext()); // we need to get a TL context for sub searchers!+ }}}}