Apache Lucene open-source search software
add basic tests for some untested TFC classes
Robert Muirc5256c244575
diff --git a/lucene/src/test/org/apache/lucene/search/TestSort.java b/lucene/src/test/org/apache/lucene/search/TestSort.javaindex 2e4b315162a..86d89c09d7a 100644--- a/lucene/src/test/org/apache/lucene/search/TestSort.java+++ b/lucene/src/test/org/apache/lucene/search/TestSort.java@@ -822,6 +822,27 @@ public class TestSort extends LuceneTestCase implements Serializable {}}+ // MultiComparatorScoringNoMaxScoreCollector+ 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);++ full.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.@@ -890,6 +911,55 @@ public class TestSort extends LuceneTestCase implements Serializable {}}+ // OutOfOrderMulti*Collector+ public void testOutOfOrderDocsScoringSortMulti() throws Exception {++ // Two Sort criteria to instantiate the multi/single comparators.+ Sort[] sort = new Sort[] {new Sort(SortField.FIELD_DOC, SortField.FIELD_SCORE) };+ boolean[][] tfcOptions = new boolean[][] {+ new boolean[] { false, false, false },+ new boolean[] { false, false, true },+ new boolean[] { false, true, false },+ new boolean[] { false, true, true },+ new boolean[] { true, false, false },+ new boolean[] { true, false, true },+ new boolean[] { true, true, false },+ new boolean[] { true, true, true },+ };+ String[] actualTFCClasses = new String[] {+ "OutOfOrderMultiComparatorNonScoringCollector",+ "OutOfOrderMultiComparatorScoringMaxScoreCollector",+ "OutOfOrderMultiComparatorScoringNoMaxScoreCollector",+ "OutOfOrderMultiComparatorScoringMaxScoreCollector",+ "OutOfOrderMultiComparatorNonScoringCollector",+ "OutOfOrderMultiComparatorScoringMaxScoreCollector",+ "OutOfOrderMultiComparatorScoringNoMaxScoreCollector",+ "OutOfOrderMultiComparatorScoringMaxScoreCollector"+ };++ BooleanQuery bq = new BooleanQuery();+ // Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2+ // which delegates to BS if there are no mandatory clauses.+ bq.add(new MatchAllDocsQuery(), Occur.SHOULD);+ // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return+ // the clause instead of BQ.+ bq.setMinimumNumberShouldMatch(1);+ for (int i = 0; i < sort.length; i++) {+ for (int j = 0; j < tfcOptions.length; j++) {+ TopDocsCollector<Entry> tdc = TopFieldCollector.create(sort[i], 10,+ tfcOptions[j][0], tfcOptions[j][1], tfcOptions[j][2], false);++ assertTrue(tdc.getClass().getName().endsWith("$"+actualTFCClasses[j]));++ full.search(bq, tdc);++ TopDocs td = tdc.topDocs();+ ScoreDoc[] sd = td.scoreDocs;+ assertEquals(10, sd.length);+ }+ }+ }+public void testSortWithScoreAndMaxScoreTrackingNoResults() throws Exception {// Two Sort criteria to instantiate the multi/single comparators.