Apache Solr open-source search software
LUCENE-1356: Allow easy extensions of TopDocCollector.
Doron Cohen80aed8ddaeb0
diff --git a/CHANGES.txt b/CHANGES.txtindex cffc80abdbd..ff5a4e4989b 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -140,6 +140,10 @@ API Changes22. LUCENE-1371: Added convenience method TopDocs Searcher.search(Query query, int n).(Mike McCandless)++23. LUCENE-1356: Allow easy extensions of TopDocCollector by turning+ constructor and fields from package to protected. (Shai Erera+ via Doron Cohen)Bug fixesdiff --git a/src/java/org/apache/lucene/search/TopDocCollector.java b/src/java/org/apache/lucene/search/TopDocCollector.javaindex 09ad58b4f23..84a51b445f2 100644--- a/src/java/org/apache/lucene/search/TopDocCollector.java+++ b/src/java/org/apache/lucene/search/TopDocCollector.java@@ -30,21 +30,34 @@ import org.apache.lucene.util.PriorityQueue;public class TopDocCollector extends HitCollector {private ScoreDoc reusableSD;-- int totalHits;- PriorityQueue hq;++ /** The total number of hits the collector encountered. */+ protected int totalHits;++ /** The priority queue which holds the top-scoring documents. */+ protected PriorityQueue hq;/** Construct to collect a given number of hits.* @param numHits the maximum number of hits to collect*/public TopDocCollector(int numHits) {- this(numHits, new HitQueue(numHits));+ this(new HitQueue(numHits));}+ /** @deprecated use TopDocCollector(hq) instead. numHits is not used by this+ * constructor. It will be removed in a future release.+ */TopDocCollector(int numHits, PriorityQueue hq) {this.hq = hq;}+ /** Constructor to collect the top-scoring documents by using the given PQ.+ * @hq the PQ to use by this instance.+ */+ protected TopDocCollector(PriorityQueue hq) {+ this.hq = hq;+ }+// javadoc inheritedpublic void collect(int doc, float score) {if (score > 0.0f) {diff --git a/src/java/org/apache/lucene/search/TopFieldDocCollector.java b/src/java/org/apache/lucene/search/TopFieldDocCollector.javaindex e6e37322ec6..e033e36e03d 100644--- a/src/java/org/apache/lucene/search/TopFieldDocCollector.java+++ b/src/java/org/apache/lucene/search/TopFieldDocCollector.java@@ -40,7 +40,7 @@ public class TopFieldDocCollector extends TopDocCollector {*/public TopFieldDocCollector(IndexReader reader, Sort sort, int numHits)throws IOException {- super(numHits, new FieldSortedHitQueue(reader, sort.fields, numHits));+ super(new FieldSortedHitQueue(reader, sort.fields, numHits));}// javadoc inherited