LUCENE-2837: only populate subSearchers if they will be used

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1056086 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2011-01-06 21:20:18 +00:00
parent 8d7d57abdc
commit 8dfb827d0c
1 changed files with 14 additions and 8 deletions

View File

@ -64,9 +64,10 @@ public class IndexSearcher {
// in the next release // in the next release
protected final ReaderContext readerContext; protected final ReaderContext readerContext;
protected final AtomicReaderContext[] leafContexts; protected final AtomicReaderContext[] leafContexts;
protected final IndexSearcher[] subSearchers;
// protected final int[] docStarts; // These are only used for multi-threaded search
private final ExecutorService executor; private final ExecutorService executor;
protected final IndexSearcher[] subSearchers;
/** The Similarity implementation used by this searcher. */ /** The Similarity implementation used by this searcher. */
private Similarity similarity = Similarity.getDefault(); private Similarity similarity = Similarity.getDefault();
@ -165,12 +166,17 @@ public class IndexSearcher {
assert context.leaves() != null : "non-atomic top-level context must have leaves"; assert context.leaves() != null : "non-atomic top-level context must have leaves";
this.leafContexts = context.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 (executor == null) {
if (leafContexts[i].reader == context.reader) { subSearchers = null;
subSearchers[i] = this; } else {
} else { subSearchers = new IndexSearcher[this.leafContexts.length];
subSearchers[i] = new IndexSearcher(leafContexts[i].reader.getTopReaderContext()); // we need to get a TL context for sub searchers! 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!
}
} }
} }
} }