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
lucene/src/java/org/apache/lucene/search

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,8 +166,12 @@ 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();
} }
if (executor == null) {
subSearchers = null;
} else {
subSearchers = new IndexSearcher[this.leafContexts.length]; subSearchers = new IndexSearcher[this.leafContexts.length];
for (int i = 0; i < subSearchers.length; i++) { // TODO do we need those IS if executor is null? for (int i = 0; i < subSearchers.length; i++) {
if (leafContexts[i].reader == context.reader) { if (leafContexts[i].reader == context.reader) {
subSearchers[i] = this; subSearchers[i] = this;
} else { } else {
@ -174,6 +179,7 @@ public class IndexSearcher {
} }
} }
} }
}
/** Return the {@link IndexReader} this searches. */ /** Return the {@link IndexReader} this searches. */
public IndexReader getIndexReader() { public IndexReader getIndexReader() {