mirror of https://github.com/apache/lucene.git
Update TestTopDocsCollector to no longer rely on the deprecated search(Query, Collector) (#13600)
This commit is contained in:
parent
97d89c661f
commit
d491dfe131
|
@ -18,6 +18,7 @@ package org.apache.lucene.search;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Field.Store;
|
||||
|
@ -41,6 +42,35 @@ import org.apache.lucene.util.BytesRef;
|
|||
|
||||
public class TestTopDocsCollector extends LuceneTestCase {
|
||||
|
||||
private static final class MyTopDocsCollectorMananger
|
||||
implements CollectorManager<MyTopDocsCollector, MyTopDocsCollector> {
|
||||
|
||||
private final int numHits;
|
||||
|
||||
MyTopDocsCollectorMananger(int numHits) {
|
||||
this.numHits = numHits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyTopDocsCollector newCollector() {
|
||||
return new MyTopDocsCollector(numHits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyTopDocsCollector reduce(Collection<MyTopDocsCollector> collectors) {
|
||||
int totalHits = 0;
|
||||
MyTopDocsCollector myTopDocsCollector = new MyTopDocsCollector(numHits);
|
||||
for (MyTopDocsCollector collector : collectors) {
|
||||
totalHits += collector.totalHits;
|
||||
for (ScoreDoc scoreDoc : collector.pq) {
|
||||
myTopDocsCollector.pq.insertWithOverflow(scoreDoc);
|
||||
}
|
||||
}
|
||||
myTopDocsCollector.totalHits = totalHits;
|
||||
return myTopDocsCollector;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MyTopDocsCollector extends TopDocsCollector<ScoreDoc> {
|
||||
|
||||
private int idx = 0;
|
||||
|
@ -125,14 +155,8 @@ public class TestTopDocsCollector extends LuceneTestCase {
|
|||
|
||||
private TopDocsCollector<ScoreDoc> doSearch(int numResults) throws IOException {
|
||||
Query q = new MatchAllDocsQuery();
|
||||
return doSearch(numResults, q);
|
||||
}
|
||||
|
||||
private TopDocsCollector<ScoreDoc> doSearch(int numResults, Query q) throws IOException {
|
||||
IndexSearcher searcher = newSearcher(reader);
|
||||
TopDocsCollector<ScoreDoc> tdc = new MyTopDocsCollector(numResults);
|
||||
searcher.search(q, tdc);
|
||||
return tdc;
|
||||
return searcher.search(q, new MyTopDocsCollectorMananger(numResults));
|
||||
}
|
||||
|
||||
private TopDocs doSearchWithThreshold(
|
||||
|
|
Loading…
Reference in New Issue