diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java index e28be104ac0..0566061f357 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestTopDocsCollector.java @@ -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 { + + private final int numHits; + + MyTopDocsCollectorMananger(int numHits) { + this.numHits = numHits; + } + + @Override + public MyTopDocsCollector newCollector() { + return new MyTopDocsCollector(numHits); + } + + @Override + public MyTopDocsCollector reduce(Collection 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 { private int idx = 0; @@ -125,14 +155,8 @@ public class TestTopDocsCollector extends LuceneTestCase { private TopDocsCollector doSearch(int numResults) throws IOException { Query q = new MatchAllDocsQuery(); - return doSearch(numResults, q); - } - - private TopDocsCollector doSearch(int numResults, Query q) throws IOException { IndexSearcher searcher = newSearcher(reader); - TopDocsCollector tdc = new MyTopDocsCollector(numResults); - searcher.search(q, tdc); - return tdc; + return searcher.search(q, new MyTopDocsCollectorMananger(numResults)); } private TopDocs doSearchWithThreshold(