Remove `supportsConcurrency` flag from top-docs collector managers. (#13977)

Our collector managers have a `supportsConcurrency` flag to optimize the case
when they are used in a single thread. This PR proposes to remove this flag now
that the optimization doesn't do much as a result of #13943.
This commit is contained in:
Adrien Grand 2024-11-05 15:36:40 +01:00
parent 7f50732cc3
commit 48026bbc25
23 changed files with 91 additions and 137 deletions

View File

@ -112,8 +112,7 @@ public abstract class ReadTask extends PerfTask {
// pulling the Weight ourselves: // pulling the Weight ourselves:
int totalHitsThreshold = withTotalHits() ? Integer.MAX_VALUE : 1; int totalHitsThreshold = withTotalHits() ? Integer.MAX_VALUE : 1;
TopFieldCollectorManager collectorManager = TopFieldCollectorManager collectorManager =
new TopFieldCollectorManager( new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold);
sort, numHits, null, totalHitsThreshold, searcher.getSlices().length > 1);
hits = searcher.search(q, collectorManager); hits = searcher.search(q, collectorManager);
} else { } else {
hits = searcher.search(q, numHits); hits = searcher.search(q, numHits);

View File

@ -564,10 +564,8 @@ public class IndexSearcher {
} }
final int cappedNumHits = Math.min(numHits, limit); final int cappedNumHits = Math.min(numHits, limit);
final boolean supportsConcurrency = getSlices().length > 1;
CollectorManager<TopScoreDocCollector, TopDocs> manager = CollectorManager<TopScoreDocCollector, TopDocs> manager =
new TopScoreDocCollectorManager( new TopScoreDocCollectorManager(cappedNumHits, after, TOTAL_HITS_THRESHOLD);
cappedNumHits, after, TOTAL_HITS_THRESHOLD, supportsConcurrency);
return search(query, manager); return search(query, manager);
} }
@ -699,12 +697,9 @@ public class IndexSearcher {
} }
final int cappedNumHits = Math.min(numHits, limit); final int cappedNumHits = Math.min(numHits, limit);
final Sort rewrittenSort = sort.rewrite(this); final Sort rewrittenSort = sort.rewrite(this);
final LeafSlice[] leafSlices = getSlices();
final boolean supportsConcurrency = leafSlices.length > 1;
final CollectorManager<TopFieldCollector, TopFieldDocs> manager = final CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager( new TopFieldCollectorManager(rewrittenSort, cappedNumHits, after, TOTAL_HITS_THRESHOLD);
rewrittenSort, cappedNumHits, after, TOTAL_HITS_THRESHOLD, supportsConcurrency);
TopFieldDocs topDocs = search(query, manager); TopFieldDocs topDocs = search(query, manager);
if (doDocScores) { if (doDocScores) {

View File

@ -46,9 +46,7 @@ public class SortRescorer extends Rescorer {
List<LeafReaderContext> leaves = searcher.getIndexReader().leaves(); List<LeafReaderContext> leaves = searcher.getIndexReader().leaves();
TopFieldCollector collector = TopFieldCollector collector =
new TopFieldCollectorManager( new TopFieldCollectorManager(sort, topN, null, Integer.MAX_VALUE).newCollector();
sort, topN, null, Integer.MAX_VALUE, searcher.getSlices().length > 1)
.newCollector();
// Now merge sort docIDs from hits, with reader's leaves: // Now merge sort docIDs from hits, with reader's leaves:
int hitUpto = 0; int hitUpto = 0;

View File

@ -35,8 +35,6 @@ public class TopFieldCollectorManager implements CollectorManager<TopFieldCollec
private final int totalHitsThreshold; private final int totalHitsThreshold;
private final MaxScoreAccumulator minScoreAcc; private final MaxScoreAccumulator minScoreAcc;
private final List<TopFieldCollector> collectors; private final List<TopFieldCollector> collectors;
private final boolean supportsConcurrency;
private boolean collectorCreated;
/** /**
* Creates a new {@link TopFieldCollectorManager} from the given arguments. * Creates a new {@link TopFieldCollectorManager} from the given arguments.
@ -53,9 +51,32 @@ public class TopFieldCollectorManager implements CollectorManager<TopFieldCollec
* count of the result will be accurate. {@link Integer#MAX_VALUE} may be used to make the hit * count of the result will be accurate. {@link Integer#MAX_VALUE} may be used to make the hit
* count accurate, but this will also make query processing slower. * count accurate, but this will also make query processing slower.
* @param supportsConcurrency to use thread-safe and slower internal states for count tracking. * @param supportsConcurrency to use thread-safe and slower internal states for count tracking.
* @deprecated Use {@link #TopFieldCollectorManager(Sort, int, FieldDoc, int)}, the
* supportsConcurrency parameter is now a no-op.
*/ */
@Deprecated
public TopFieldCollectorManager( public TopFieldCollectorManager(
Sort sort, int numHits, FieldDoc after, int totalHitsThreshold, boolean supportsConcurrency) { Sort sort, int numHits, FieldDoc after, int totalHitsThreshold, boolean supportsConcurrency) {
this(sort, numHits, after, totalHitsThreshold);
}
/**
* Creates a new {@link TopFieldCollectorManager} from the given arguments, with thread-safe
* internal states.
*
* <p><b>NOTE</b>: The instances returned by this method pre-allocate a full array of length
* <code>numHits</code>.
*
* @param sort the sort criteria (SortFields).
* @param numHits the number of results to collect.
* @param after the previous doc after which matching docs will be collected.
* @param totalHitsThreshold the number of docs to count accurately. If the query matches more
* than {@code totalHitsThreshold} hits then its hit count will be a lower bound. On the other
* hand if the query matches less than or exactly {@code totalHitsThreshold} hits then the hit
* count of the result will be accurate. {@link Integer#MAX_VALUE} may be used to make the hit
* count accurate, but this will also make query processing slower.
*/
public TopFieldCollectorManager(Sort sort, int numHits, FieldDoc after, int totalHitsThreshold) {
if (totalHitsThreshold < 0) { if (totalHitsThreshold < 0) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"totalHitsThreshold must be >= 0, got " + totalHitsThreshold); "totalHitsThreshold must be >= 0, got " + totalHitsThreshold);
@ -88,35 +109,11 @@ public class TopFieldCollectorManager implements CollectorManager<TopFieldCollec
this.sort = sort; this.sort = sort;
this.numHits = numHits; this.numHits = numHits;
this.after = after; this.after = after;
this.supportsConcurrency = supportsConcurrency;
this.totalHitsThreshold = totalHitsThreshold; this.totalHitsThreshold = totalHitsThreshold;
this.minScoreAcc = this.minScoreAcc = totalHitsThreshold != Integer.MAX_VALUE ? new MaxScoreAccumulator() : null;
supportsConcurrency && totalHitsThreshold != Integer.MAX_VALUE
? new MaxScoreAccumulator()
: null;
this.collectors = new ArrayList<>(); this.collectors = new ArrayList<>();
} }
/**
* Creates a new {@link TopFieldCollectorManager} from the given arguments, with thread-safe
* internal states.
*
* <p><b>NOTE</b>: The instances returned by this method pre-allocate a full array of length
* <code>numHits</code>.
*
* @param sort the sort criteria (SortFields).
* @param numHits the number of results to collect.
* @param after the previous doc after which matching docs will be collected.
* @param totalHitsThreshold the number of docs to count accurately. If the query matches more
* than {@code totalHitsThreshold} hits then its hit count will be a lower bound. On the other
* hand if the query matches less than or exactly {@code totalHitsThreshold} hits then the hit
* count of the result will be accurate. {@link Integer#MAX_VALUE} may be used to make the hit
* count accurate, but this will also make query processing slower.
*/
public TopFieldCollectorManager(Sort sort, int numHits, FieldDoc after, int totalHitsThreshold) {
this(sort, numHits, after, totalHitsThreshold, true);
}
/** /**
* Creates a new {@link TopFieldCollectorManager} from the given arguments, with thread-safe * Creates a new {@link TopFieldCollectorManager} from the given arguments, with thread-safe
* internal states. * internal states.
@ -138,13 +135,6 @@ public class TopFieldCollectorManager implements CollectorManager<TopFieldCollec
@Override @Override
public TopFieldCollector newCollector() { public TopFieldCollector newCollector() {
if (collectorCreated && supportsConcurrency == false) {
throw new IllegalStateException(
"This TopFieldCollectorManager was created without concurrency (supportsConcurrency=false), but multiple collectors are being created");
} else {
collectorCreated = true;
}
FieldValueHitQueue<FieldValueHitQueue.Entry> queue = FieldValueHitQueue<FieldValueHitQueue.Entry> queue =
FieldValueHitQueue.create(sort.getSort(), numHits); FieldValueHitQueue.create(sort.getSort(), numHits);

View File

@ -31,8 +31,6 @@ public class TopScoreDocCollectorManager
private final ScoreDoc after; private final ScoreDoc after;
private final int totalHitsThreshold; private final int totalHitsThreshold;
private final MaxScoreAccumulator minScoreAcc; private final MaxScoreAccumulator minScoreAcc;
private final boolean supportsConcurrency;
private boolean collectorCreated;
/** /**
* Creates a new {@link TopScoreDocCollectorManager} given the number of hits to collect and the * Creates a new {@link TopScoreDocCollectorManager} given the number of hits to collect and the
@ -54,28 +52,13 @@ public class TopScoreDocCollectorManager
* hand if the query matches less than or exactly {@code totalHitsThreshold} hits then the hit * hand if the query matches less than or exactly {@code totalHitsThreshold} hits then the hit
* count of the result will be accurate. {@link Integer#MAX_VALUE} may be used to make the hit * count of the result will be accurate. {@link Integer#MAX_VALUE} may be used to make the hit
* count accurate, but this will also make query processing slower. * count accurate, but this will also make query processing slower.
* @param supportsConcurrency to use thread-safe and slower internal states for count tracking. * @deprecated Use {@link #TopScoreDocCollectorManager(int, ScoreDoc, int)}, the
* supportsConcurrency parameter is now a no-op.
*/ */
@Deprecated
public TopScoreDocCollectorManager( public TopScoreDocCollectorManager(
int numHits, ScoreDoc after, int totalHitsThreshold, boolean supportsConcurrency) { int numHits, ScoreDoc after, int totalHitsThreshold, boolean supportsConcurrency) {
if (totalHitsThreshold < 0) { this(numHits, after, totalHitsThreshold);
throw new IllegalArgumentException(
"totalHitsThreshold must be >= 0, got " + totalHitsThreshold);
}
if (numHits <= 0) {
throw new IllegalArgumentException(
"numHits must be > 0; please use TotalHitCountCollectorManager if you just need the total hit count");
}
this.numHits = numHits;
this.after = after;
this.supportsConcurrency = supportsConcurrency;
this.totalHitsThreshold = Math.max(totalHitsThreshold, numHits);
this.minScoreAcc =
supportsConcurrency && totalHitsThreshold != Integer.MAX_VALUE
? new MaxScoreAccumulator()
: null;
} }
/** /**
@ -100,7 +83,20 @@ public class TopScoreDocCollectorManager
* count accurate, but this will also make query processing slower. * count accurate, but this will also make query processing slower.
*/ */
public TopScoreDocCollectorManager(int numHits, ScoreDoc after, int totalHitsThreshold) { public TopScoreDocCollectorManager(int numHits, ScoreDoc after, int totalHitsThreshold) {
this(numHits, after, totalHitsThreshold, true); if (totalHitsThreshold < 0) {
throw new IllegalArgumentException(
"totalHitsThreshold must be >= 0, got " + totalHitsThreshold);
}
if (numHits <= 0) {
throw new IllegalArgumentException(
"numHits must be > 0; please use TotalHitCountCollectorManager if you just need the total hit count");
}
this.numHits = numHits;
this.after = after;
this.totalHitsThreshold = Math.max(totalHitsThreshold, numHits);
this.minScoreAcc = totalHitsThreshold != Integer.MAX_VALUE ? new MaxScoreAccumulator() : null;
} }
/** /**
@ -129,13 +125,6 @@ public class TopScoreDocCollectorManager
@Override @Override
public TopScoreDocCollector newCollector() { public TopScoreDocCollector newCollector() {
if (collectorCreated && supportsConcurrency == false) {
throw new IllegalStateException(
"This TopScoreDocCollectorManager was created without concurrency (supportsConcurrency=false), but multiple collectors are being created");
} else {
collectorCreated = true;
}
if (after == null) { if (after == null) {
return new TopScoreDocCollector.SimpleTopScoreDocCollector( return new TopScoreDocCollector.SimpleTopScoreDocCollector(
numHits, totalHitsThreshold, minScoreAcc); numHits, totalHitsThreshold, minScoreAcc);

View File

@ -67,7 +67,7 @@ public class TestIndexWriterMaxDocs extends LuceneTestCase {
assertEquals(IndexWriter.MAX_DOCS, ir.numDocs()); assertEquals(IndexWriter.MAX_DOCS, ir.numDocs());
IndexSearcher searcher = new IndexSearcher(ir); IndexSearcher searcher = new IndexSearcher(ir);
TopScoreDocCollectorManager collectorManager = TopScoreDocCollectorManager collectorManager =
new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE, true); new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE);
TopDocs hits = searcher.search(new TermQuery(new Term("field", "text")), collectorManager); TopDocs hits = searcher.search(new TermQuery(new Term("field", "text")), collectorManager);
assertEquals(IndexWriter.MAX_DOCS, hits.totalHits.value()); assertEquals(IndexWriter.MAX_DOCS, hits.totalHits.value());

View File

@ -155,7 +155,7 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
private final Set<Scorer> tqsSet = new HashSet<>(); private final Set<Scorer> tqsSet = new HashSet<>();
MyCollector() { MyCollector() {
super(new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE, false).newCollector()); super(new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE).newCollector());
} }
@Override @Override

View File

@ -98,7 +98,7 @@ public class TestElevationComparator extends LuceneTestCase {
TopDocs topDocs = TopDocs topDocs =
searcher.search( searcher.search(
newq.build(), new TopFieldCollectorManager(sort, 50, null, Integer.MAX_VALUE, true)); newq.build(), new TopFieldCollectorManager(sort, 50, null, Integer.MAX_VALUE));
int nDocsReturned = topDocs.scoreDocs.length; int nDocsReturned = topDocs.scoreDocs.length;
assertEquals(4, nDocsReturned); assertEquals(4, nDocsReturned);

View File

@ -81,8 +81,7 @@ public class TestNeedsScores extends LuceneTestCase {
assertEquals(5, searcher.count(constantScore)); assertEquals(5, searcher.count(constantScore));
TopDocs hits = TopDocs hits =
searcher.search( searcher.search(constantScore, new TopScoreDocCollectorManager(5, null, Integer.MAX_VALUE));
constantScore, new TopScoreDocCollectorManager(5, null, Integer.MAX_VALUE, true));
assertEquals(5, hits.totalHits.value()); assertEquals(5, hits.totalHits.value());
// Queries that support dynamic pruning like top-score or top-doc queries that do not compute // Queries that support dynamic pruning like top-score or top-doc queries that do not compute

View File

@ -110,8 +110,7 @@ public class TestPositiveScoresOnlyCollector extends LuceneTestCase {
writer.close(); writer.close();
Scorer s = new SimpleScorer(); Scorer s = new SimpleScorer();
TopDocsCollector<ScoreDoc> tdc = TopDocsCollector<ScoreDoc> tdc =
new TopScoreDocCollectorManager(scores.length, null, Integer.MAX_VALUE, false) new TopScoreDocCollectorManager(scores.length, null, Integer.MAX_VALUE).newCollector();
.newCollector();
Collector c = new PositiveScoresOnlyCollector(tdc); Collector c = new PositiveScoresOnlyCollector(tdc);
LeafCollector ac = c.getLeafCollector(ir.leaves().get(0)); LeafCollector ac = c.getLeafCollector(ir.leaves().get(0));
ac.setScorer(s); ac.setScorer(s);

View File

@ -234,10 +234,10 @@ public class TestSearchAfter extends LuceneTestCase {
allManager = new TopScoreDocCollectorManager(maxDoc, null, Integer.MAX_VALUE); allManager = new TopScoreDocCollectorManager(maxDoc, null, Integer.MAX_VALUE);
doScores = false; doScores = false;
} else if (sort == Sort.RELEVANCE) { } else if (sort == Sort.RELEVANCE) {
allManager = new TopFieldCollectorManager(sort, maxDoc, null, Integer.MAX_VALUE, true); allManager = new TopFieldCollectorManager(sort, maxDoc, null, Integer.MAX_VALUE);
doScores = true; doScores = true;
} else { } else {
allManager = new TopFieldCollectorManager(sort, maxDoc, null, Integer.MAX_VALUE, true); allManager = new TopFieldCollectorManager(sort, maxDoc, null, Integer.MAX_VALUE);
doScores = random().nextBoolean(); doScores = random().nextBoolean();
} }
all = searcher.search(query, allManager); all = searcher.search(query, allManager);
@ -268,15 +268,13 @@ public class TestSearchAfter extends LuceneTestCase {
if (VERBOSE) { if (VERBOSE) {
System.out.println(" iter lastBottom=" + lastBottom); System.out.println(" iter lastBottom=" + lastBottom);
} }
pagedManager = pagedManager = new TopScoreDocCollectorManager(pageSize, lastBottom, Integer.MAX_VALUE);
new TopScoreDocCollectorManager(pageSize, lastBottom, Integer.MAX_VALUE, true);
} else { } else {
if (VERBOSE) { if (VERBOSE) {
System.out.println(" iter lastBottom=" + lastBottom); System.out.println(" iter lastBottom=" + lastBottom);
} }
pagedManager = pagedManager =
new TopFieldCollectorManager( new TopFieldCollectorManager(sort, pageSize, (FieldDoc) lastBottom, Integer.MAX_VALUE);
sort, pageSize, (FieldDoc) lastBottom, Integer.MAX_VALUE, true);
} }
paged = searcher.search(query, pagedManager); paged = searcher.search(query, pagedManager);
if (doScores) { if (doScores) {

View File

@ -237,7 +237,7 @@ public class TestSortOptimization extends LuceneTestCase {
sortField2.setMissingValue(0L); // set a competitive missing value sortField2.setMissingValue(0L); // set a competitive missing value
final Sort sort = new Sort(sortField1, sortField2); final Sort sort = new Sort(sortField1, sortField2);
CollectorManager<TopFieldCollector, TopFieldDocs> manager = CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold, true); new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold);
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager); TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
assertEquals(topDocs.scoreDocs.length, numHits); assertEquals(topDocs.scoreDocs.length, numHits);
assertEquals( assertEquals(
@ -264,7 +264,7 @@ public class TestSortOptimization extends LuceneTestCase {
sortField.setMissingValue(Long.MAX_VALUE); // set a competitive missing value sortField.setMissingValue(Long.MAX_VALUE); // set a competitive missing value
final Sort sort = new Sort(sortField); final Sort sort = new Sort(sortField);
CollectorManager<TopFieldCollector, TopFieldDocs> manager = CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager(sort, numHits, after, totalHitsThreshold, true); new TopFieldCollectorManager(sort, numHits, after, totalHitsThreshold);
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager); TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
assertEquals(topDocs.scoreDocs.length, numHits); assertEquals(topDocs.scoreDocs.length, numHits);
assertNonCompetitiveHitsAreSkipped(topDocs.totalHits.value(), numDocs); assertNonCompetitiveHitsAreSkipped(topDocs.totalHits.value(), numDocs);
@ -279,7 +279,7 @@ public class TestSortOptimization extends LuceneTestCase {
sortField.setMissingValue(Long.MAX_VALUE); // set a competitive missing value sortField.setMissingValue(Long.MAX_VALUE); // set a competitive missing value
final Sort sort = new Sort(sortField); final Sort sort = new Sort(sortField);
CollectorManager<TopFieldCollector, TopFieldDocs> manager = CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager(sort, numHits, after, totalHitsThreshold, true); new TopFieldCollectorManager(sort, numHits, after, totalHitsThreshold);
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager); TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
assertEquals(topDocs.scoreDocs.length, numHits); assertEquals(topDocs.scoreDocs.length, numHits);
assertNonCompetitiveHitsAreSkipped(topDocs.totalHits.value(), numDocs); assertNonCompetitiveHitsAreSkipped(topDocs.totalHits.value(), numDocs);
@ -347,7 +347,7 @@ public class TestSortOptimization extends LuceneTestCase {
sortField.setMissingValue(0L); // missing value is not competitive sortField.setMissingValue(0L); // missing value is not competitive
final Sort sort = new Sort(sortField); final Sort sort = new Sort(sortField);
CollectorManager<TopFieldCollector, TopFieldDocs> manager = CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold, true); new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold);
topDocs1 = searcher.search(new MatchAllDocsQuery(), manager); topDocs1 = searcher.search(new MatchAllDocsQuery(), manager);
assertNonCompetitiveHitsAreSkipped(topDocs1.totalHits.value(), numDocs); assertNonCompetitiveHitsAreSkipped(topDocs1.totalHits.value(), numDocs);
} }
@ -358,7 +358,7 @@ public class TestSortOptimization extends LuceneTestCase {
final Sort sort = new Sort(sortField); final Sort sort = new Sort(sortField);
sortField.setOptimizeSortWithPoints(false); sortField.setOptimizeSortWithPoints(false);
CollectorManager<TopFieldCollector, TopFieldDocs> manager = CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold, true); new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold);
topDocs2 = searcher.search(new MatchAllDocsQuery(), manager); topDocs2 = searcher.search(new MatchAllDocsQuery(), manager);
// assert that the resulting hits are the same // assert that the resulting hits are the same
assertEquals(topDocs1.scoreDocs.length, topDocs2.scoreDocs.length); assertEquals(topDocs1.scoreDocs.length, topDocs2.scoreDocs.length);
@ -381,7 +381,7 @@ public class TestSortOptimization extends LuceneTestCase {
sortField2.setMissingValue(0L); // missing value is not competitive sortField2.setMissingValue(0L); // missing value is not competitive
final Sort multiSorts = new Sort(new SortField[] {sortField1, sortField2}); final Sort multiSorts = new Sort(new SortField[] {sortField1, sortField2});
CollectorManager<TopFieldCollector, TopFieldDocs> manager = CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager(multiSorts, numHits, null, totalHitsThreshold, true); new TopFieldCollectorManager(multiSorts, numHits, null, totalHitsThreshold);
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager); TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
// can't optimization with NumericDocValues when there are multiple comparators // can't optimization with NumericDocValues when there are multiple comparators
assertEquals(topDocs.totalHits.value(), numDocs); assertEquals(topDocs.totalHits.value(), numDocs);
@ -959,7 +959,7 @@ public class TestSortOptimization extends LuceneTestCase {
// test search // test search
int numHits = 1 + random().nextInt(100); int numHits = 1 + random().nextInt(100);
CollectorManager<TopFieldCollector, TopFieldDocs> manager = CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager(new Sort(sortField), numHits, null, numHits, true); new TopFieldCollectorManager(new Sort(sortField), numHits, null, numHits);
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager); TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
for (int i = 0; i < topDocs.scoreDocs.length; i++) { for (int i = 0; i < topDocs.scoreDocs.length; i++) {
long expectedSeqNo = seqNos.get(i); long expectedSeqNo = seqNos.get(i);
@ -1010,12 +1010,12 @@ public class TestSortOptimization extends LuceneTestCase {
int expectedHits = Math.min(numDocs - visitedHits, batch); int expectedHits = Math.min(numDocs - visitedHits, batch);
CollectorManager<TopFieldCollector, TopFieldDocs> manager = CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager(sort, batch, (FieldDoc) after, totalHitsThreshold, true); new TopFieldCollectorManager(sort, batch, (FieldDoc) after, totalHitsThreshold);
TopDocs topDocs = searcher.search(query, manager); TopDocs topDocs = searcher.search(query, manager);
ScoreDoc[] scoreDocs = topDocs.scoreDocs; ScoreDoc[] scoreDocs = topDocs.scoreDocs;
CollectorManager<TopFieldCollector, TopFieldDocs> manager2 = CollectorManager<TopFieldCollector, TopFieldDocs> manager2 =
new TopFieldCollectorManager(sort2, batch, (FieldDoc) after, totalHitsThreshold, true); new TopFieldCollectorManager(sort2, batch, (FieldDoc) after, totalHitsThreshold);
TopDocs topDocs2 = searcher.search(query, manager2); TopDocs topDocs2 = searcher.search(query, manager2);
ScoreDoc[] scoreDocs2 = topDocs2.scoreDocs; ScoreDoc[] scoreDocs2 = topDocs2.scoreDocs;
@ -1210,7 +1210,7 @@ public class TestSortOptimization extends LuceneTestCase {
final int totalHitsThreshold = 5; final int totalHitsThreshold = 5;
CollectorManager<TopFieldCollector, TopFieldDocs> manager = CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold, true); new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold);
IndexSearcher searcher = IndexSearcher searcher =
newSearcher(reader, random().nextBoolean(), random().nextBoolean(), false); newSearcher(reader, random().nextBoolean(), random().nextBoolean(), false);
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager); TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
@ -1240,7 +1240,7 @@ public class TestSortOptimization extends LuceneTestCase {
IndexSearcher searcher = newSearcher(reader, true, true, false); IndexSearcher searcher = newSearcher(reader, true, true, false);
Query query = new MatchAllDocsQuery(); Query query = new MatchAllDocsQuery();
CollectorManager<TopFieldCollector, TopFieldDocs> manager = CollectorManager<TopFieldCollector, TopFieldDocs> manager =
new TopFieldCollectorManager(sort, n, after, n, true); new TopFieldCollectorManager(sort, n, after, n);
TopDocs topDocs = searcher.search(query, manager); TopDocs topDocs = searcher.search(query, manager);
IndexSearcher unoptimizedSearcher = IndexSearcher unoptimizedSearcher =
newSearcher(new NoIndexDirectoryReader(reader), true, true, false); newSearcher(new NoIndexDirectoryReader(reader), true, true, false);

View File

@ -160,8 +160,7 @@ public class TestTopDocsCollector extends LuceneTestCase {
int numResults, int thresHold, Query q, IndexReader indexReader) throws IOException { int numResults, int thresHold, Query q, IndexReader indexReader) throws IOException {
IndexSearcher searcher = newSearcher(indexReader, true, true, false); IndexSearcher searcher = newSearcher(indexReader, true, true, false);
TopScoreDocCollectorManager collectorManager = TopScoreDocCollectorManager collectorManager =
new TopScoreDocCollectorManager( new TopScoreDocCollectorManager(numResults, null, thresHold);
numResults, null, thresHold, searcher.getSlices().length > 1);
return searcher.search(q, collectorManager); return searcher.search(q, collectorManager);
} }
@ -169,8 +168,7 @@ public class TestTopDocsCollector extends LuceneTestCase {
int numResults, int threshold, Query q, IndexReader indexReader) throws IOException { int numResults, int threshold, Query q, IndexReader indexReader) throws IOException {
IndexSearcher searcher = newSearcher(indexReader, true, true, true); IndexSearcher searcher = newSearcher(indexReader, true, true, true);
TopScoreDocCollectorManager collectorManager = TopScoreDocCollectorManager collectorManager =
new TopScoreDocCollectorManager( new TopScoreDocCollectorManager(numResults, null, threshold);
numResults, null, threshold, searcher.getSlices().length > 1);
return searcher.search(q, collectorManager); return searcher.search(q, collectorManager);
} }

View File

@ -56,7 +56,7 @@ public class TestTopDocsMerge extends LuceneTestCase {
public TopDocs search(Weight weight, int topN) throws IOException { public TopDocs search(Weight weight, int topN) throws IOException {
TopScoreDocCollector collector = TopScoreDocCollector collector =
new TopScoreDocCollectorManager(topN, null, Integer.MAX_VALUE, false).newCollector(); new TopScoreDocCollectorManager(topN, null, Integer.MAX_VALUE).newCollector();
searchLeaf(ctx, 0, DocIdSetIterator.NO_MORE_DOCS, weight, collector); searchLeaf(ctx, 0, DocIdSetIterator.NO_MORE_DOCS, weight, collector);
return collector.topDocs(); return collector.topDocs();
} }
@ -348,8 +348,7 @@ public class TestTopDocsMerge extends LuceneTestCase {
subHits = subSearcher.search(w, numHits); subHits = subSearcher.search(w, numHits);
} else { } else {
final TopFieldCollector c = final TopFieldCollector c =
new TopFieldCollectorManager(sort, numHits, null, Integer.MAX_VALUE, false) new TopFieldCollectorManager(sort, numHits, null, Integer.MAX_VALUE).newCollector();
.newCollector();
subSearcher.search(w, c); subSearcher.search(w, c);
subHits = c.topDocs(0, numHits); subHits = c.topDocs(0, numHits);
} }

View File

@ -76,8 +76,7 @@ public class TestTopFieldCollector extends LuceneTestCase {
throws IOException { throws IOException {
IndexSearcher searcher = newSearcher(indexReader); IndexSearcher searcher = newSearcher(indexReader);
TopFieldCollectorManager manager = TopFieldCollectorManager manager =
new TopFieldCollectorManager( new TopFieldCollectorManager(sort, numResults, null, thresHold);
sort, numResults, null, thresHold, searcher.getSlices().length > 1);
return searcher.search(q, manager); return searcher.search(q, manager);
} }
@ -87,8 +86,7 @@ public class TestTopFieldCollector extends LuceneTestCase {
IndexSearcher searcher = newSearcher(indexReader, true, true, true); IndexSearcher searcher = newSearcher(indexReader, true, true, true);
TopFieldCollectorManager collectorManager = TopFieldCollectorManager collectorManager =
new TopFieldCollectorManager( new TopFieldCollectorManager(sort, numResults, null, threshold);
sort, numResults, null, threshold, searcher.getSlices().length > 1);
TopDocs topDoc = searcher.search(q, collectorManager); TopDocs topDoc = searcher.search(q, collectorManager);
@ -122,7 +120,7 @@ public class TestTopFieldCollector extends LuceneTestCase {
for (int i = 0; i < sort.length; i++) { for (int i = 0; i < sort.length; i++) {
Query q = new MatchAllDocsQuery(); Query q = new MatchAllDocsQuery();
TopFieldCollectorManager tdc = TopFieldCollectorManager tdc =
new TopFieldCollectorManager(sort[i], 10, null, Integer.MAX_VALUE, false); new TopFieldCollectorManager(sort[i], 10, null, Integer.MAX_VALUE);
TopDocs td = is.search(q, tdc); TopDocs td = is.search(q, tdc);
ScoreDoc[] sd = td.scoreDocs; ScoreDoc[] sd = td.scoreDocs;
for (int j = 0; j < sd.length; j++) { for (int j = 0; j < sd.length; j++) {
@ -384,7 +382,7 @@ public class TestTopFieldCollector extends LuceneTestCase {
Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC), new Sort()}; Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC), new Sort()};
for (int i = 0; i < sort.length; i++) { for (int i = 0; i < sort.length; i++) {
TopDocsCollector<Entry> tdc = TopDocsCollector<Entry> tdc =
new TopFieldCollectorManager(sort[i], 10, null, Integer.MAX_VALUE, false).newCollector(); new TopFieldCollectorManager(sort[i], 10, null, Integer.MAX_VALUE).newCollector();
TopDocs td = tdc.topDocs(); TopDocs td = tdc.topDocs();
assertEquals(0, td.totalHits.value()); assertEquals(0, td.totalHits.value());
} }
@ -716,18 +714,17 @@ public class TestTopFieldCollector extends LuceneTestCase {
try (IndexReader reader = DirectoryReader.open(w)) { try (IndexReader reader = DirectoryReader.open(w)) {
IndexSearcher searcher = new IndexSearcher(reader); IndexSearcher searcher = new IndexSearcher(reader);
TopFieldCollectorManager collectorManager = TopFieldCollectorManager collectorManager = new TopFieldCollectorManager(sort, 2, null, 10);
new TopFieldCollectorManager(sort, 2, null, 10, true);
TopDocs topDocs = searcher.search(new TermQuery(new Term("f", "foo")), collectorManager); TopDocs topDocs = searcher.search(new TermQuery(new Term("f", "foo")), collectorManager);
assertEquals(10, topDocs.totalHits.value()); assertEquals(10, topDocs.totalHits.value());
assertEquals(TotalHits.Relation.EQUAL_TO, topDocs.totalHits.relation()); assertEquals(TotalHits.Relation.EQUAL_TO, topDocs.totalHits.relation());
collectorManager = new TopFieldCollectorManager(sort, 2, null, 2, true); collectorManager = new TopFieldCollectorManager(sort, 2, null, 2);
topDocs = searcher.search(new TermQuery(new Term("f", "foo")), collectorManager); topDocs = searcher.search(new TermQuery(new Term("f", "foo")), collectorManager);
assertTrue(10 >= topDocs.totalHits.value()); assertTrue(10 >= topDocs.totalHits.value());
assertEquals(TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO, topDocs.totalHits.relation()); assertEquals(TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO, topDocs.totalHits.relation());
collectorManager = new TopFieldCollectorManager(sort, 10, null, 2, true); collectorManager = new TopFieldCollectorManager(sort, 10, null, 2);
topDocs = searcher.search(new TermQuery(new Term("f", "foo")), collectorManager); topDocs = searcher.search(new TermQuery(new Term("f", "foo")), collectorManager);
assertEquals(10, topDocs.totalHits.value()); assertEquals(10, topDocs.totalHits.value());
assertEquals(TotalHits.Relation.EQUAL_TO, topDocs.totalHits.relation()); assertEquals(TotalHits.Relation.EQUAL_TO, topDocs.totalHits.relation());

View File

@ -197,9 +197,8 @@ public class DrillSideways {
limit = 1; // the collector does not alow numHits = 0 limit = 1; // the collector does not alow numHits = 0
} }
final int fTopN = Math.min(topN, limit); final int fTopN = Math.min(topN, limit);
final boolean supportsConcurrency = searcher.getSlices().length > 1;
final TopFieldCollectorManager collectorManager = final TopFieldCollectorManager collectorManager =
new TopFieldCollectorManager(sort, fTopN, after, Integer.MAX_VALUE, supportsConcurrency); new TopFieldCollectorManager(sort, fTopN, after, Integer.MAX_VALUE);
final ConcurrentDrillSidewaysResult<TopFieldDocs> r = search(query, collectorManager); final ConcurrentDrillSidewaysResult<TopFieldDocs> r = search(query, collectorManager);
TopFieldDocs topDocs = r.collectorResult; TopFieldDocs topDocs = r.collectorResult;
@ -230,9 +229,8 @@ public class DrillSideways {
limit = 1; // the collector does not alow numHits = 0 limit = 1; // the collector does not alow numHits = 0
} }
final int fTopN = Math.min(topN, limit); final int fTopN = Math.min(topN, limit);
final boolean supportsConcurrency = searcher.getSlices().length > 1;
final TopScoreDocCollectorManager collectorManager = final TopScoreDocCollectorManager collectorManager =
new TopScoreDocCollectorManager(fTopN, after, Integer.MAX_VALUE, supportsConcurrency); new TopScoreDocCollectorManager(fTopN, after, Integer.MAX_VALUE);
final ConcurrentDrillSidewaysResult<TopDocs> r = search(query, collectorManager); final ConcurrentDrillSidewaysResult<TopDocs> r = search(query, collectorManager);
return new DrillSidewaysResult( return new DrillSidewaysResult(
r.facets, r.facets,

View File

@ -285,11 +285,11 @@ public class FacetsCollectorManager implements CollectorManager<FacetsCollector,
throw new IllegalArgumentException("after must be a FieldDoc; got " + after); throw new IllegalArgumentException("after must be a FieldDoc; got " + after);
} }
TopFieldCollectorManager topFieldCollectorManager = TopFieldCollectorManager topFieldCollectorManager =
new TopFieldCollectorManager(sort, n, (FieldDoc) after, Integer.MAX_VALUE, true); new TopFieldCollectorManager(sort, n, (FieldDoc) after, Integer.MAX_VALUE);
multiCollectorManager = new MultiCollectorManager(topFieldCollectorManager, fcm); multiCollectorManager = new MultiCollectorManager(topFieldCollectorManager, fcm);
} else { } else {
TopScoreDocCollectorManager topScoreDocCollectorManager = TopScoreDocCollectorManager topScoreDocCollectorManager =
new TopScoreDocCollectorManager(n, after, Integer.MAX_VALUE, true); new TopScoreDocCollectorManager(n, after, Integer.MAX_VALUE);
multiCollectorManager = new MultiCollectorManager(topScoreDocCollectorManager, fcm); multiCollectorManager = new MultiCollectorManager(topScoreDocCollectorManager, fcm);
} }
Object[] result = searcher.search(q, multiCollectorManager); Object[] result = searcher.search(q, multiCollectorManager);

View File

@ -295,13 +295,12 @@ public class BlockGroupingCollector extends SimpleCollector {
"cannot sort by relevance within group: needsScores=false"); "cannot sort by relevance within group: needsScores=false");
} }
collector = collector =
new TopScoreDocCollectorManager(maxDocsPerGroup, null, Integer.MAX_VALUE, false) new TopScoreDocCollectorManager(maxDocsPerGroup, null, Integer.MAX_VALUE)
.newCollector(); .newCollector();
} else { } else {
// Sort by fields // Sort by fields
collector = collector =
new TopFieldCollectorManager( new TopFieldCollectorManager(withinGroupSort, maxDocsPerGroup, null, Integer.MAX_VALUE)
withinGroupSort, maxDocsPerGroup, null, Integer.MAX_VALUE, false)
.newCollector(); // TODO: disable exact counts? .newCollector(); // TODO: disable exact counts?
} }

View File

@ -129,7 +129,7 @@ public class TopGroupsCollector<T> extends SecondPassGroupingCollector<T> {
() -> () ->
new TopDocsAndMaxScoreCollector( new TopDocsAndMaxScoreCollector(
true, true,
new TopScoreDocCollectorManager(maxDocsPerGroup, null, Integer.MAX_VALUE, false) new TopScoreDocCollectorManager(maxDocsPerGroup, null, Integer.MAX_VALUE)
.newCollector(), .newCollector(),
null); null);
} else { } else {
@ -137,7 +137,7 @@ public class TopGroupsCollector<T> extends SecondPassGroupingCollector<T> {
() -> { () -> {
TopFieldCollector topDocsCollector = TopFieldCollector topDocsCollector =
new TopFieldCollectorManager( new TopFieldCollectorManager(
withinGroupSort, maxDocsPerGroup, null, Integer.MAX_VALUE, false) withinGroupSort, maxDocsPerGroup, null, Integer.MAX_VALUE)
.newCollector(); // TODO: disable exact counts? .newCollector(); // TODO: disable exact counts?
MaxScoreCollector maxScoreCollector = getMaxScores ? new MaxScoreCollector() : null; MaxScoreCollector maxScoreCollector = getMaxScores ? new MaxScoreCollector() : null;
return new TopDocsAndMaxScoreCollector(false, topDocsCollector, maxScoreCollector); return new TopDocsAndMaxScoreCollector(false, topDocsCollector, maxScoreCollector);

View File

@ -468,7 +468,7 @@ public class TestJoinUtil extends LuceneTestCase {
final BitSet actualResult = new FixedBitSet(indexSearcher.getIndexReader().maxDoc()); final BitSet actualResult = new FixedBitSet(indexSearcher.getIndexReader().maxDoc());
final TopScoreDocCollector topScoreDocCollector = final TopScoreDocCollector topScoreDocCollector =
new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE, false).newCollector(); new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE).newCollector();
indexSearcher.search( indexSearcher.search(
joinQuery, MultiCollector.wrap(new BitSetCollector(actualResult), topScoreDocCollector)); joinQuery, MultiCollector.wrap(new BitSetCollector(actualResult), topScoreDocCollector));
assertBitSet(expectedResult, actualResult, indexSearcher); assertBitSet(expectedResult, actualResult, indexSearcher);
@ -1546,7 +1546,7 @@ public class TestJoinUtil extends LuceneTestCase {
// be also testing TopDocsCollector... // be also testing TopDocsCollector...
final BitSet actualResult = new FixedBitSet(indexSearcher.getIndexReader().maxDoc()); final BitSet actualResult = new FixedBitSet(indexSearcher.getIndexReader().maxDoc());
final TopScoreDocCollector topScoreDocCollector = final TopScoreDocCollector topScoreDocCollector =
new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE, false).newCollector(); new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE).newCollector();
indexSearcher.search( indexSearcher.search(
joinQuery, joinQuery,
MultiCollector.wrap(new BitSetCollector(actualResult), topScoreDocCollector)); MultiCollector.wrap(new BitSetCollector(actualResult), topScoreDocCollector));

View File

@ -315,8 +315,7 @@ public final class SearchImpl extends LukeModel implements Search {
} else { } else {
int hitsThreshold = exactHitsCount ? Integer.MAX_VALUE : DEFAULT_TOTAL_HITS_THRESHOLD; int hitsThreshold = exactHitsCount ? Integer.MAX_VALUE : DEFAULT_TOTAL_HITS_THRESHOLD;
TopScoreDocCollectorManager collectorManager = TopScoreDocCollectorManager collectorManager =
new TopScoreDocCollectorManager( new TopScoreDocCollectorManager(pageSize, after, hitsThreshold);
pageSize, after, hitsThreshold, searcher.getSlices().length > 1);
topDocs = searcher.search(query, collectorManager); topDocs = searcher.search(query, collectorManager);
} }

View File

@ -739,8 +739,7 @@ public class AnalyzingInfixSuggester extends Lookup implements Closeable {
searcherMgrReadLock.unlock(); searcherMgrReadLock.unlock();
} }
try { try {
TopFieldCollectorManager c = TopFieldCollectorManager c = new TopFieldCollectorManager(SORT, num, null, 1);
new TopFieldCollectorManager(SORT, num, null, 1, searcher.getSlices().length > 1);
// System.out.println("got searcher=" + searcher); // System.out.println("got searcher=" + searcher);
TopFieldDocs hits = searcher.search(finalQuery, c); TopFieldDocs hits = searcher.search(finalQuery, c);

View File

@ -705,12 +705,10 @@ public class CheckHits {
private static void doCheckTopScores(Query query, IndexSearcher searcher, int numHits) private static void doCheckTopScores(Query query, IndexSearcher searcher, int numHits)
throws IOException { throws IOException {
boolean supportsConcurrency = searcher.getSlices().length > 1;
TopScoreDocCollectorManager complete = TopScoreDocCollectorManager complete =
new TopScoreDocCollectorManager( new TopScoreDocCollectorManager(numHits, null, Integer.MAX_VALUE); // COMPLETE
numHits, null, Integer.MAX_VALUE, supportsConcurrency); // COMPLETE
TopScoreDocCollectorManager topScores = TopScoreDocCollectorManager topScores =
new TopScoreDocCollectorManager(numHits, null, 1, supportsConcurrency); // TOP_SCORES new TopScoreDocCollectorManager(numHits, null, 1); // TOP_SCORES
TopDocs completeTopDocs = searcher.search(query, complete); TopDocs completeTopDocs = searcher.search(query, complete);
TopDocs topScoresTopDocs = searcher.search(query, topScores); TopDocs topScoresTopDocs = searcher.search(query, topScores);
checkEqual(query, completeTopDocs.scoreDocs, topScoresTopDocs.scoreDocs); checkEqual(query, completeTopDocs.scoreDocs, topScoresTopDocs.scoreDocs);