public PagingFieldCollector( FieldValueHitQueue<Entry> queue, FieldDoc after, int numHits, boolean fillFields, boolean trackDocScores, boolean trackMaxScore) { super(queue, numHits, fillFields); this.queue = queue; this.trackDocScores = trackDocScores; this.trackMaxScore = trackMaxScore; this.after = after; comparators = queue.getComparators(); reverseMul = queue.getReverseMul(); // Must set maxScore to NEG_INF, or otherwise Math.max always returns NaN. maxScore = Float.NEGATIVE_INFINITY; // Tell all comparators their top value: for(int i=0;i<comparators.length;i++) { @SuppressWarnings("unchecked") FieldComparator<Object> comparator = (FieldComparator<Object>) comparators[i]; comparator.setTopValue(after.fields[i]); } }
public void testSortWithoutFillFields() throws Exception { // There was previously a bug in TopFieldCollector when fillFields was set // to false - the same doc and score was set in ScoreDoc[] array. This test // asserts that if fillFields is false, the documents are set properly. It // does not use Searcher's default search methods (with Sort) since all set // fillFields to true. Sort[] sort = new Sort[] { new Sort(SortField.FIELD_DOC), new Sort() }; for(int i = 0; i < sort.length; i++) { Query q = new MatchAllDocsQuery(); TopDocsCollector<Entry> tdc = TopFieldCollector.create(sort[i], 10, false, false, false, true); is.search(q, tdc); ScoreDoc[] sd = tdc.topDocs().scoreDocs; for(int j = 1; j < sd.length; j++) { assertTrue(sd[j].doc != sd[j - 1].doc); } } }
public void testSortWithoutScoreTracking() throws Exception { // Two Sort criteria to instantiate the multi/single comparators. Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC), new Sort() }; for(int i = 0; i < sort.length; i++) { Query q = new MatchAllDocsQuery(); TopDocsCollector<Entry> tdc = TopFieldCollector.create(sort[i], 10, true, false, false, true); is.search(q, tdc); TopDocs td = tdc.topDocs(); ScoreDoc[] sd = td.scoreDocs; for(int j = 0; j < sd.length; j++) { assertTrue(Float.isNaN(sd[j].score)); } assertTrue(Float.isNaN(td.getMaxScore())); } }
public void testSortWithScoreNoMaxScoreTracking() throws Exception { // Two Sort criteria to instantiate the multi/single comparators. Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC), new Sort() }; for(int i = 0; i < sort.length; i++) { Query q = new MatchAllDocsQuery(); TopDocsCollector<Entry> tdc = TopFieldCollector.create(sort[i], 10, true, true, false, true); is.search(q, tdc); TopDocs td = tdc.topDocs(); ScoreDoc[] sd = td.scoreDocs; for(int j = 0; j < sd.length; j++) { assertTrue(!Float.isNaN(sd[j].score)); } assertTrue(Float.isNaN(td.getMaxScore())); } }
public void testSortWithScoreNoMaxScoreTrackingMulti() throws Exception { // Two Sort criteria to instantiate the multi/single comparators. Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC, SortField.FIELD_SCORE) }; for(int i = 0; i < sort.length; i++) { Query q = new MatchAllDocsQuery(); TopDocsCollector<Entry> tdc = TopFieldCollector.create(sort[i], 10, true, true, false, true); is.search(q, tdc); TopDocs td = tdc.topDocs(); ScoreDoc[] sd = td.scoreDocs; for(int j = 0; j < sd.length; j++) { assertTrue(!Float.isNaN(sd[j].score)); } assertTrue(Float.isNaN(td.getMaxScore())); } }
public void testSortWithScoreAndMaxScoreTracking() throws Exception { // Two Sort criteria to instantiate the multi/single comparators. Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC), new Sort() }; for(int i = 0; i < sort.length; i++) { Query q = new MatchAllDocsQuery(); TopDocsCollector<Entry> tdc = TopFieldCollector.create(sort[i], 10, true, true, true, true); is.search(q, tdc); TopDocs td = tdc.topDocs(); ScoreDoc[] sd = td.scoreDocs; for(int j = 0; j < sd.length; j++) { assertTrue(!Float.isNaN(sd[j].score)); } assertTrue(!Float.isNaN(td.getMaxScore())); } }
public OneComparatorNonScoringCollector(FieldValueHitQueue<Entry> queue, int numHits, boolean fillFields) { super(queue, numHits, fillFields); this.queue = queue; comparator = queue.getComparators()[0]; reverseMul = queue.getReverseMul()[0]; }
public MultiComparatorNonScoringCollector(FieldValueHitQueue<Entry> queue, int numHits, boolean fillFields) { super(queue, numHits, fillFields); this.queue = queue; comparators = queue.getComparators(); reverseMul = queue.getReverseMul(); }
@Override protected void populateResults(ScoreDoc[] results, int howMany) { if (fillFields) { // avoid casting if unnecessary. FieldValueHitQueue<Entry> queue = (FieldValueHitQueue<Entry>) pq; for (int i = howMany - 1; i >= 0; i--) { results[i] = queue.fillFields(queue.pop()); } } else { for (int i = howMany - 1; i >= 0; i--) { Entry entry = pq.pop(); results[i] = new FieldDoc(entry.doc, entry.score); } } }
@Override protected TopDocs newTopDocs(ScoreDoc[] results, int start) { if (results == null) { results = EMPTY_SCOREDOCS; // Set maxScore to NaN, in case this is a maxScore tracking collector. maxScore = Float.NaN; } // If this is a maxScoring tracking collector and there were no results, return new TopFieldDocs(totalHits, results, ((FieldValueHitQueue<Entry>) pq).getFields(), maxScore); }
public void testSortWithScoreAndMaxScoreTrackingNoResults() throws Exception { // Two Sort criteria to instantiate the multi/single comparators. Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC), new Sort() }; for(int i = 0; i < sort.length; i++) { TopDocsCollector<Entry> tdc = TopFieldCollector.create(sort[i], 10, true, true, true, true); TopDocs td = tdc.topDocs(); assertEquals(0, td.totalHits); assertTrue(Float.isNaN(td.getMaxScore())); } }
public PagingFieldCollector( FieldValueHitQueue<Entry> queue, FieldDoc after, int numHits, boolean fillFields, boolean trackDocScores, boolean trackMaxScore) { super(queue, numHits, fillFields); this.queue = queue; this.trackDocScores = trackDocScores; this.trackMaxScore = trackMaxScore; this.after = after; comparators = queue.getComparators(); reverseMul = queue.getReverseMul(); // Must set maxScore to NEG_INF, or otherwise Math.max always returns NaN. maxScore = Float.NEGATIVE_INFINITY; }