mirror of https://github.com/apache/lucene.git
Remove usage of TopScoreDocCollector + TopFieldCollector deprecated methods (#create, #createSharedManager) (#13500)
These methods were deprecated in #240 which is part of Lucene 10.0. Addresses #13499
This commit is contained in:
parent
481ca2d30f
commit
8a7d4842cc
|
@ -244,6 +244,8 @@ Other
|
|||
|
||||
* GITHUB#13332: Improve MissingDoclet linter to check records correctly. (Uwe Schindler)
|
||||
|
||||
* GITHUB#13499: Remove usage of TopScoreDocCollector + TopFieldCollector deprecated methods (#create, #createSharedManager) (Jakub Slowinski)
|
||||
|
||||
======================== Lucene 9.12.0 =======================
|
||||
|
||||
API Changes
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.apache.lucene.benchmark.byTask.PerfRunData;
|
|||
import org.apache.lucene.benchmark.byTask.feeds.QueryMaker;
|
||||
import org.apache.lucene.benchmark.byTask.utils.Config;
|
||||
import org.apache.lucene.search.Collector;
|
||||
import org.apache.lucene.search.TopScoreDocCollector;
|
||||
import org.apache.lucene.search.TopScoreDocCollectorManager;
|
||||
|
||||
/** Does search w/ a custom collector */
|
||||
public class SearchWithCollectorTask extends SearchTask {
|
||||
|
@ -49,7 +49,8 @@ public class SearchWithCollectorTask extends SearchTask {
|
|||
protected Collector createCollector() throws Exception {
|
||||
Collector collector = null;
|
||||
if (clnName.equalsIgnoreCase("topScoreDoc") == true) {
|
||||
collector = TopScoreDocCollector.create(numHits(), Integer.MAX_VALUE);
|
||||
collector =
|
||||
new TopScoreDocCollectorManager(numHits(), null, Integer.MAX_VALUE, false).newCollector();
|
||||
} else if (clnName.length() > 0) {
|
||||
collector = Class.forName(clnName).asSubclass(Collector.class).getConstructor().newInstance();
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.apache.lucene.search.TotalHits.Relation;
|
|||
/**
|
||||
* A {@link Collector} that sorts by {@link SortField} using {@link FieldComparator}s.
|
||||
*
|
||||
* <p>See the {@link #create(org.apache.lucene.search.Sort, int, int)} method for instantiating a
|
||||
* TopFieldCollector.
|
||||
* <p>See the constructor of {@link TopFieldCollectorManager} for instantiating a
|
||||
* TopFieldCollectorManager with support for concurrency in IndexSearcher.
|
||||
*
|
||||
* @lucene.experimental
|
||||
*/
|
||||
|
|
|
@ -156,7 +156,7 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
|
|||
private final Set<Scorer> tqsSet = new HashSet<>();
|
||||
|
||||
MyCollector() {
|
||||
super(TopScoreDocCollector.create(10, Integer.MAX_VALUE));
|
||||
super(new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE, false).newCollector());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -98,7 +98,7 @@ public class TestElevationComparator extends LuceneTestCase {
|
|||
|
||||
TopDocs topDocs =
|
||||
searcher.search(
|
||||
newq.build(), TopFieldCollector.createSharedManager(sort, 50, null, Integer.MAX_VALUE));
|
||||
newq.build(), new TopFieldCollectorManager(sort, 50, null, Integer.MAX_VALUE, true));
|
||||
int nDocsReturned = topDocs.scoreDocs.length;
|
||||
|
||||
assertEquals(4, nDocsReturned);
|
||||
|
|
|
@ -82,7 +82,7 @@ public class TestNeedsScores extends LuceneTestCase {
|
|||
|
||||
TopDocs hits =
|
||||
searcher.search(
|
||||
constantScore, TopScoreDocCollector.createSharedManager(5, null, Integer.MAX_VALUE));
|
||||
constantScore, new TopScoreDocCollectorManager(5, null, Integer.MAX_VALUE, true));
|
||||
assertEquals(5, hits.totalHits.value);
|
||||
|
||||
// Queries that support dynamic pruning like top-score or top-doc queries that do not compute
|
||||
|
|
|
@ -109,7 +109,9 @@ public class TestPositiveScoresOnlyCollector extends LuceneTestCase {
|
|||
IndexReader ir = writer.getReader();
|
||||
writer.close();
|
||||
Scorer s = new SimpleScorer();
|
||||
TopDocsCollector<ScoreDoc> tdc = TopScoreDocCollector.create(scores.length, Integer.MAX_VALUE);
|
||||
TopDocsCollector<ScoreDoc> tdc =
|
||||
new TopScoreDocCollectorManager(scores.length, null, Integer.MAX_VALUE, false)
|
||||
.newCollector();
|
||||
Collector c = new PositiveScoresOnlyCollector(tdc);
|
||||
LeafCollector ac = c.getLeafCollector(ir.leaves().get(0));
|
||||
ac.setScorer(s);
|
||||
|
|
|
@ -231,13 +231,13 @@ public class TestSearchAfter extends LuceneTestCase {
|
|||
final boolean doScores;
|
||||
final CollectorManager<?, ? extends TopDocs> allManager;
|
||||
if (sort == null) {
|
||||
allManager = TopScoreDocCollector.createSharedManager(maxDoc, null, Integer.MAX_VALUE);
|
||||
allManager = new TopScoreDocCollectorManager(maxDoc, null, Integer.MAX_VALUE);
|
||||
doScores = false;
|
||||
} else if (sort == Sort.RELEVANCE) {
|
||||
allManager = TopFieldCollector.createSharedManager(sort, maxDoc, null, Integer.MAX_VALUE);
|
||||
allManager = new TopFieldCollectorManager(sort, maxDoc, null, Integer.MAX_VALUE, true);
|
||||
doScores = true;
|
||||
} else {
|
||||
allManager = TopFieldCollector.createSharedManager(sort, maxDoc, null, Integer.MAX_VALUE);
|
||||
allManager = new TopFieldCollectorManager(sort, maxDoc, null, Integer.MAX_VALUE, true);
|
||||
doScores = random().nextBoolean();
|
||||
}
|
||||
all = searcher.search(query, allManager);
|
||||
|
@ -269,20 +269,14 @@ public class TestSearchAfter extends LuceneTestCase {
|
|||
System.out.println(" iter lastBottom=" + lastBottom);
|
||||
}
|
||||
pagedManager =
|
||||
TopScoreDocCollector.createSharedManager(pageSize, lastBottom, Integer.MAX_VALUE);
|
||||
new TopScoreDocCollectorManager(pageSize, lastBottom, Integer.MAX_VALUE, true);
|
||||
} else {
|
||||
if (VERBOSE) {
|
||||
System.out.println(" iter lastBottom=" + lastBottom);
|
||||
}
|
||||
if (sort == Sort.RELEVANCE) {
|
||||
pagedManager =
|
||||
TopFieldCollector.createSharedManager(
|
||||
sort, pageSize, (FieldDoc) lastBottom, Integer.MAX_VALUE);
|
||||
} else {
|
||||
pagedManager =
|
||||
TopFieldCollector.createSharedManager(
|
||||
sort, pageSize, (FieldDoc) lastBottom, Integer.MAX_VALUE);
|
||||
}
|
||||
pagedManager =
|
||||
new TopFieldCollectorManager(
|
||||
sort, pageSize, (FieldDoc) lastBottom, Integer.MAX_VALUE, true);
|
||||
}
|
||||
paged = searcher.search(query, pagedManager);
|
||||
if (doScores) {
|
||||
|
|
|
@ -237,7 +237,7 @@ public class TestSortOptimization extends LuceneTestCase {
|
|||
sortField2.setMissingValue(0L); // set a competitive missing value
|
||||
final Sort sort = new Sort(sortField1, sortField2);
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
|
||||
TopFieldCollector.createSharedManager(sort, numHits, null, totalHitsThreshold);
|
||||
new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold, true);
|
||||
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
|
||||
assertEquals(topDocs.scoreDocs.length, numHits);
|
||||
assertEquals(
|
||||
|
@ -264,7 +264,7 @@ public class TestSortOptimization extends LuceneTestCase {
|
|||
sortField.setMissingValue(Long.MAX_VALUE); // set a competitive missing value
|
||||
final Sort sort = new Sort(sortField);
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
|
||||
TopFieldCollector.createSharedManager(sort, numHits, after, totalHitsThreshold);
|
||||
new TopFieldCollectorManager(sort, numHits, after, totalHitsThreshold, true);
|
||||
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
|
||||
assertEquals(topDocs.scoreDocs.length, numHits);
|
||||
assertNonCompetitiveHitsAreSkipped(topDocs.totalHits.value, numDocs);
|
||||
|
@ -279,7 +279,7 @@ public class TestSortOptimization extends LuceneTestCase {
|
|||
sortField.setMissingValue(Long.MAX_VALUE); // set a competitive missing value
|
||||
final Sort sort = new Sort(sortField);
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
|
||||
TopFieldCollector.createSharedManager(sort, numHits, after, totalHitsThreshold);
|
||||
new TopFieldCollectorManager(sort, numHits, after, totalHitsThreshold, true);
|
||||
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
|
||||
assertEquals(topDocs.scoreDocs.length, numHits);
|
||||
assertNonCompetitiveHitsAreSkipped(topDocs.totalHits.value, numDocs);
|
||||
|
@ -323,7 +323,7 @@ public class TestSortOptimization extends LuceneTestCase {
|
|||
sortField.setMissingValue(0L); // missing value is not competitive
|
||||
final Sort sort = new Sort(sortField);
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
|
||||
TopFieldCollector.createSharedManager(sort, numHits, null, totalHitsThreshold);
|
||||
new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold, true);
|
||||
topDocs1 = searcher.search(new MatchAllDocsQuery(), manager);
|
||||
assertNonCompetitiveHitsAreSkipped(topDocs1.totalHits.value, numDocs);
|
||||
}
|
||||
|
@ -334,7 +334,7 @@ public class TestSortOptimization extends LuceneTestCase {
|
|||
final Sort sort = new Sort(sortField);
|
||||
sortField.setOptimizeSortWithPoints(false);
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
|
||||
TopFieldCollector.createSharedManager(sort, numHits, null, totalHitsThreshold);
|
||||
new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold, true);
|
||||
topDocs2 = searcher.search(new MatchAllDocsQuery(), manager);
|
||||
// assert that the resulting hits are the same
|
||||
assertEquals(topDocs1.scoreDocs.length, topDocs2.scoreDocs.length);
|
||||
|
@ -357,7 +357,7 @@ public class TestSortOptimization extends LuceneTestCase {
|
|||
sortField2.setMissingValue(0L); // missing value is not competitive
|
||||
final Sort multiSorts = new Sort(new SortField[] {sortField1, sortField2});
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
|
||||
TopFieldCollector.createSharedManager(multiSorts, numHits, null, totalHitsThreshold);
|
||||
new TopFieldCollectorManager(multiSorts, numHits, null, totalHitsThreshold, true);
|
||||
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
|
||||
// can't optimization with NumericDocValues when there are multiple comparators
|
||||
assertEquals(topDocs.totalHits.value, numDocs);
|
||||
|
@ -935,7 +935,7 @@ public class TestSortOptimization extends LuceneTestCase {
|
|||
// test search
|
||||
int numHits = 1 + random().nextInt(100);
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
|
||||
TopFieldCollector.createSharedManager(new Sort(sortField), numHits, null, numHits);
|
||||
new TopFieldCollectorManager(new Sort(sortField), numHits, null, numHits, true);
|
||||
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
|
||||
for (int i = 0; i < topDocs.scoreDocs.length; i++) {
|
||||
long expectedSeqNo = seqNos.get(i);
|
||||
|
@ -986,12 +986,12 @@ public class TestSortOptimization extends LuceneTestCase {
|
|||
int expectedHits = Math.min(numDocs - visitedHits, batch);
|
||||
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
|
||||
TopFieldCollector.createSharedManager(sort, batch, (FieldDoc) after, totalHitsThreshold);
|
||||
new TopFieldCollectorManager(sort, batch, (FieldDoc) after, totalHitsThreshold, true);
|
||||
TopDocs topDocs = searcher.search(query, manager);
|
||||
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
|
||||
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager2 =
|
||||
TopFieldCollector.createSharedManager(sort2, batch, (FieldDoc) after, totalHitsThreshold);
|
||||
new TopFieldCollectorManager(sort2, batch, (FieldDoc) after, totalHitsThreshold, true);
|
||||
TopDocs topDocs2 = searcher.search(query, manager2);
|
||||
ScoreDoc[] scoreDocs2 = topDocs2.scoreDocs;
|
||||
|
||||
|
@ -1186,7 +1186,7 @@ public class TestSortOptimization extends LuceneTestCase {
|
|||
final int totalHitsThreshold = 5;
|
||||
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
|
||||
TopFieldCollector.createSharedManager(sort, numHits, null, totalHitsThreshold);
|
||||
new TopFieldCollectorManager(sort, numHits, null, totalHitsThreshold, true);
|
||||
IndexSearcher searcher =
|
||||
newSearcher(reader, random().nextBoolean(), random().nextBoolean(), false);
|
||||
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), manager);
|
||||
|
@ -1216,7 +1216,7 @@ public class TestSortOptimization extends LuceneTestCase {
|
|||
IndexSearcher searcher = newSearcher(reader, true, true, false);
|
||||
Query query = new MatchAllDocsQuery();
|
||||
CollectorManager<TopFieldCollector, TopFieldDocs> manager =
|
||||
TopFieldCollector.createSharedManager(sort, n, after, n);
|
||||
new TopFieldCollectorManager(sort, n, after, n, true);
|
||||
TopDocs topDocs = searcher.search(query, manager);
|
||||
IndexSearcher unoptimizedSearcher =
|
||||
newSearcher(new NoIndexDirectoryReader(reader), true, true, false);
|
||||
|
|
|
@ -55,7 +55,8 @@ public class TestTopDocsMerge extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public TopDocs search(Weight weight, int topN) throws IOException {
|
||||
TopScoreDocCollector collector = TopScoreDocCollector.create(topN, Integer.MAX_VALUE);
|
||||
TopScoreDocCollector collector =
|
||||
new TopScoreDocCollectorManager(topN, null, Integer.MAX_VALUE, false).newCollector();
|
||||
search(ctx, weight, collector);
|
||||
return collector.topDocs();
|
||||
}
|
||||
|
@ -346,7 +347,9 @@ public class TestTopDocsMerge extends LuceneTestCase {
|
|||
if (sort == null) {
|
||||
subHits = subSearcher.search(w, numHits);
|
||||
} else {
|
||||
final TopFieldCollector c = TopFieldCollector.create(sort, numHits, Integer.MAX_VALUE);
|
||||
final TopFieldCollector c =
|
||||
new TopFieldCollectorManager(sort, numHits, null, Integer.MAX_VALUE, false)
|
||||
.newCollector();
|
||||
subSearcher.search(w, c);
|
||||
subHits = c.topDocs(0, numHits);
|
||||
}
|
||||
|
|
|
@ -34,8 +34,9 @@ import org.apache.lucene.search.Sort;
|
|||
import org.apache.lucene.search.TopDocs;
|
||||
import org.apache.lucene.search.TopDocsCollector;
|
||||
import org.apache.lucene.search.TopFieldCollector;
|
||||
import org.apache.lucene.search.TopFieldCollectorManager;
|
||||
import org.apache.lucene.search.TopFieldDocs;
|
||||
import org.apache.lucene.search.TopScoreDocCollector;
|
||||
import org.apache.lucene.search.TopScoreDocCollectorManager;
|
||||
import org.apache.lucene.search.TotalHitCountCollector;
|
||||
import org.apache.lucene.search.TotalHits;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
|
@ -253,13 +254,11 @@ public class FacetsCollector extends SimpleCollector {
|
|||
throw new IllegalArgumentException("after must be a FieldDoc; got " + after);
|
||||
}
|
||||
hitsCollector =
|
||||
TopFieldCollector.create(
|
||||
sort,
|
||||
n,
|
||||
(FieldDoc) after,
|
||||
Integer.MAX_VALUE); // TODO: can we disable exact hit counts
|
||||
new TopFieldCollectorManager(sort, n, (FieldDoc) after, Integer.MAX_VALUE, false)
|
||||
.newCollector(); // TODO: can we disable exact hit counts
|
||||
} else {
|
||||
hitsCollector = TopScoreDocCollector.create(n, after, Integer.MAX_VALUE);
|
||||
hitsCollector =
|
||||
new TopScoreDocCollectorManager(n, after, Integer.MAX_VALUE, false).newCollector();
|
||||
}
|
||||
searcher.search(q, MultiCollector.wrap(hitsCollector, fc));
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ import org.apache.lucene.search.Sort;
|
|||
import org.apache.lucene.search.SortField;
|
||||
import org.apache.lucene.search.TopDocs;
|
||||
import org.apache.lucene.search.TopDocsCollector;
|
||||
import org.apache.lucene.search.TopFieldCollector;
|
||||
import org.apache.lucene.search.TopScoreDocCollector;
|
||||
import org.apache.lucene.search.TopFieldCollectorManager;
|
||||
import org.apache.lucene.search.TopScoreDocCollectorManager;
|
||||
import org.apache.lucene.search.TotalHits;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
|
@ -294,12 +294,15 @@ public class BlockGroupingCollector extends SimpleCollector {
|
|||
throw new IllegalArgumentException(
|
||||
"cannot sort by relevance within group: needsScores=false");
|
||||
}
|
||||
collector = TopScoreDocCollector.create(maxDocsPerGroup, Integer.MAX_VALUE);
|
||||
collector =
|
||||
new TopScoreDocCollectorManager(maxDocsPerGroup, null, Integer.MAX_VALUE, false)
|
||||
.newCollector();
|
||||
} else {
|
||||
// Sort by fields
|
||||
collector =
|
||||
TopFieldCollector.create(
|
||||
withinGroupSort, maxDocsPerGroup, Integer.MAX_VALUE); // TODO: disable exact counts?
|
||||
new TopFieldCollectorManager(
|
||||
withinGroupSort, maxDocsPerGroup, null, Integer.MAX_VALUE, false)
|
||||
.newCollector(); // TODO: disable exact counts?
|
||||
}
|
||||
|
||||
float groupMaxScore = needsScores ? Float.NEGATIVE_INFINITY : Float.NaN;
|
||||
|
|
|
@ -31,7 +31,8 @@ import org.apache.lucene.search.Sort;
|
|||
import org.apache.lucene.search.TopDocs;
|
||||
import org.apache.lucene.search.TopDocsCollector;
|
||||
import org.apache.lucene.search.TopFieldCollector;
|
||||
import org.apache.lucene.search.TopScoreDocCollector;
|
||||
import org.apache.lucene.search.TopFieldCollectorManager;
|
||||
import org.apache.lucene.search.TopScoreDocCollectorManager;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
|
@ -127,15 +128,17 @@ public class TopGroupsCollector<T> extends SecondPassGroupingCollector<T> {
|
|||
supplier =
|
||||
() ->
|
||||
new TopDocsAndMaxScoreCollector(
|
||||
true, TopScoreDocCollector.create(maxDocsPerGroup, Integer.MAX_VALUE), null);
|
||||
true,
|
||||
new TopScoreDocCollectorManager(maxDocsPerGroup, null, Integer.MAX_VALUE, false)
|
||||
.newCollector(),
|
||||
null);
|
||||
} else {
|
||||
supplier =
|
||||
() -> {
|
||||
TopFieldCollector topDocsCollector =
|
||||
TopFieldCollector.create(
|
||||
withinGroupSort,
|
||||
maxDocsPerGroup,
|
||||
Integer.MAX_VALUE); // TODO: disable exact counts?
|
||||
new TopFieldCollectorManager(
|
||||
withinGroupSort, maxDocsPerGroup, null, Integer.MAX_VALUE, false)
|
||||
.newCollector(); // TODO: disable exact counts?
|
||||
MaxScoreCollector maxScoreCollector = getMaxScores ? new MaxScoreCollector() : null;
|
||||
return new TopDocsAndMaxScoreCollector(false, topDocsCollector, maxScoreCollector);
|
||||
};
|
||||
|
|
|
@ -468,7 +468,7 @@ public class TestJoinUtil extends LuceneTestCase {
|
|||
|
||||
final BitSet actualResult = new FixedBitSet(indexSearcher.getIndexReader().maxDoc());
|
||||
final TopScoreDocCollector topScoreDocCollector =
|
||||
TopScoreDocCollector.create(10, Integer.MAX_VALUE);
|
||||
new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE, false).newCollector();
|
||||
indexSearcher.search(
|
||||
joinQuery, MultiCollector.wrap(new BitSetCollector(actualResult), topScoreDocCollector));
|
||||
assertBitSet(expectedResult, actualResult, indexSearcher);
|
||||
|
@ -1546,7 +1546,7 @@ public class TestJoinUtil extends LuceneTestCase {
|
|||
// be also testing TopDocsCollector...
|
||||
final BitSet actualResult = new FixedBitSet(indexSearcher.getIndexReader().maxDoc());
|
||||
final TopScoreDocCollector topScoreDocCollector =
|
||||
TopScoreDocCollector.create(10, Integer.MAX_VALUE);
|
||||
new TopScoreDocCollectorManager(10, null, Integer.MAX_VALUE, false).newCollector();
|
||||
indexSearcher.search(
|
||||
joinQuery,
|
||||
MultiCollector.wrap(new BitSetCollector(actualResult), topScoreDocCollector));
|
||||
|
|
Loading…
Reference in New Issue