@@ -331,33 +331,11 @@ private void testNumericDocValuesOptimizationWithMissingValues(
331331 final DirectoryReader reader = DirectoryReader .open (writer );
332332 writer .close ();
333333 final int numHits = 3 ;
334- TopDocs topDocs1 ;
335- TopDocs topDocs2 ;
336-
337334 { // Test that optimization is run with NumericDocValues when missing value is NOT competitive
338335 final SortField sortField = new SortField ("my_field" , SortField .Type .LONG , true , 0L );
339336 final Sort sort = new Sort (sortField );
340- topDocs1 = assertSearchHits (reader , sort , numHits , null );
341- assertNonCompetitiveHitsAreSkipped (topDocs1 .totalHits .value (), numDocs );
342- }
343- { // Test that sort on sorted numeric field without sort optimization and with sort optimization
344- // produce the same results
345- final SortField sortField = new SortField ("my_field" , SortField .Type .LONG , true , 0L );
346- final Sort sort = new Sort (sortField );
347- sortField .setOptimizeSortWithPoints (false );
348- topDocs2 = assertSearchHits (reader , sort , numHits , null );
349- // assert that the resulting hits are the same
350- assertEquals (topDocs1 .scoreDocs .length , topDocs2 .scoreDocs .length );
351- assertEquals (topDocs1 .scoreDocs .length , numHits );
352- ScoreDoc [] scoreDocs1 = topDocs1 .scoreDocs ;
353- ScoreDoc [] scoreDocs2 = topDocs2 .scoreDocs ;
354- for (int i = 0 ; i < numHits ; i ++) {
355- FieldDoc fieldDoc = (FieldDoc ) scoreDocs1 [i ];
356- FieldDoc fieldDoc2 = (FieldDoc ) scoreDocs2 [i ];
357- assertEquals (fieldDoc .fields [0 ], fieldDoc2 .fields [0 ]);
358- assertEquals (fieldDoc .doc , fieldDoc2 .doc );
359- }
360- assertTrue (topDocs1 .totalHits .value () < topDocs2 .totalHits .value ());
337+ TopDocs topDocs = assertSearchHits (reader , sort , numHits , null );
338+ assertNonCompetitiveHitsAreSkipped (topDocs .totalHits .value (), numDocs );
361339 }
362340
363341 { // Test that we can't do optimization via NumericDocValues when there are multiple comparators
@@ -795,25 +773,15 @@ public void testPointValidation() throws IOException {
795773 assertThrows (
796774 IllegalArgumentException .class ,
797775 () -> searcher .search (MatchAllDocsQuery .INSTANCE , 1 , new Sort (longSortOnIntField )));
798- // assert that when sort optimization is disabled we can use LONG sort on int field
799- longSortOnIntField .setOptimizeSortWithIndexedData (false );
800- searcher .search (MatchAllDocsQuery .INSTANCE , 1 , new Sort (longSortOnIntField ));
801-
802776 SortField intSortOnLongField = new SortField ("longField" , SortField .Type .INT );
803777 assertThrows (
804778 IllegalArgumentException .class ,
805779 () -> searcher .search (MatchAllDocsQuery .INSTANCE , 1 , new Sort (intSortOnLongField )));
806- // assert that when sort optimization is disabled we can use INT sort on long field
807- intSortOnLongField .setOptimizeSortWithIndexedData (false );
808- searcher .search (MatchAllDocsQuery .INSTANCE , 1 , new Sort (intSortOnLongField ));
809780
810781 SortField intSortOnIntRangeField = new SortField ("intRange" , SortField .Type .INT );
811782 assertThrows (
812783 IllegalArgumentException .class ,
813784 () -> searcher .search (MatchAllDocsQuery .INSTANCE , 1 , new Sort (intSortOnIntRangeField )));
814- // assert that when sort optimization is disabled we can use INT sort on intRange field
815- intSortOnIntRangeField .setOptimizeSortWithIndexedData (false );
816- searcher .search (MatchAllDocsQuery .INSTANCE , 1 , new Sort (intSortOnIntRangeField ));
817785
818786 reader .close ();
819787 dir .close ();
@@ -948,14 +916,8 @@ public void testSortOptimizationOnSortedNumericField() throws IOException {
948916 RandomPicks .randomFrom (random (), SortedNumericSelector .Type .values ());
949917 boolean reverse = random ().nextBoolean ();
950918 final SortField sortField = LongField .newSortField ("my_field" , reverse , type );
951- sortField .setOptimizeSortWithIndexedData (false );
952- final Sort sort = new Sort (sortField ); // sort without sort optimization
953- final SortField sortField2 = LongField .newSortField ("my_field" , reverse , type );
954- final Sort sort2 = new Sort (sortField2 ); // sort with sort optimization
955-
956- long expectedCollectedHits = 0 ;
957- long collectedHits = 0 ;
958- long collectedHits2 = 0 ;
919+ final Sort sort = new Sort (sortField ); // sort with sort optimization
920+
959921 int visitedHits = 0 ;
960922 FieldDoc after = null ;
961923 while (visitedHits < numDocs ) {
@@ -965,30 +927,14 @@ public void testSortOptimizationOnSortedNumericField() throws IOException {
965927 TopDocs topDocs = assertSearchHits (reader , sort , batch , after );
966928 ScoreDoc [] scoreDocs = topDocs .scoreDocs ;
967929
968- TopDocs topDocs2 = assertSearchHits (reader , sort2 , batch , after );
969- ScoreDoc [] scoreDocs2 = topDocs2 .scoreDocs ;
970-
971- // assert that the resulting hits are the same
972930 assertEquals (expectedHits , topDocs .scoreDocs .length );
973- assertEquals (topDocs .scoreDocs .length , topDocs2 .scoreDocs .length );
974931 for (int i = 0 ; i < scoreDocs .length ; i ++) {
975- FieldDoc fieldDoc = (FieldDoc ) scoreDocs [i ];
976- FieldDoc fieldDoc2 = (FieldDoc ) scoreDocs2 [i ];
977- assertEquals (fieldDoc .fields [0 ], fieldDoc2 .fields [0 ]);
978- assertEquals (fieldDoc .doc , fieldDoc2 .doc );
979932 visitedHits ++;
980933 }
981934
982- expectedCollectedHits += numDocs ;
983- collectedHits += topDocs .totalHits .value ();
984- collectedHits2 += topDocs2 .totalHits .value ();
985935 after = (FieldDoc ) scoreDocs [expectedHits - 1 ];
986936 }
987937 assertEquals (visitedHits , numDocs );
988- assertEquals (expectedCollectedHits , collectedHits );
989- // assert that the second sort with optimization collected less or equal hits
990- assertTrue (collectedHits >= collectedHits2 );
991- // System.out.println(expectedCollectedHits + "\t" + collectedHits + "\t" + collectedHits2);
992938
993939 reader .close ();
994940 dir .close ();
@@ -1099,7 +1045,7 @@ private void testStringSortOptimization(
10991045 final DirectoryReader reader = DirectoryReader .open (writer );
11001046 writer .close ();
11011047 doTestStringSortOptimization (reader );
1102- doTestStringSortOptimizationDisabled ( reader );
1048+
11031049 reader .close ();
11041050 dir .close ();
11051051 }
@@ -1203,12 +1149,6 @@ private void testStringSortOptimizationFieldMissingInSegment(
12031149 "my_field" , true , SortedSetSelector .Type .MIN , SortField .STRING_LAST );
12041150 Sort sort = new Sort (sortField );
12051151 TopDocs topDocs = assertSearchHits (reader , sort , numHits , null );
1206-
1207- sortField .setOptimizeSortWithIndexedData (false );
1208- sort = new Sort (sortField );
1209- TopDocs unpruned = assertSearchHits (reader , sort , numHits , null );
1210-
1211- CheckHits .checkEqual (MatchAllDocsQuery .INSTANCE , topDocs .scoreDocs , unpruned .scoreDocs );
12121152 }
12131153
12141154 { // descending sort with missing-first: once the queue fills from the first segment,
@@ -1227,12 +1167,6 @@ private void testStringSortOptimizationFieldMissingInSegment(
12271167 "my_field" , false , SortedSetSelector .Type .MIN , SortField .STRING_FIRST );
12281168 Sort sort = new Sort (sortField );
12291169 TopDocs topDocs = assertSearchHits (reader , sort , numHits , null );
1230-
1231- sortField .setOptimizeSortWithIndexedData (false );
1232- sort = new Sort (sortField );
1233- TopDocs unpruned = assertSearchHits (reader , sort , numHits , null );
1234-
1235- CheckHits .checkEqual (MatchAllDocsQuery .INSTANCE , topDocs .scoreDocs , unpruned .scoreDocs );
12361170 }
12371171
12381172 reader .close ();
@@ -1342,20 +1276,6 @@ private void doTestStringSortOptimization(DirectoryReader reader) throws IOExcep
13421276 }
13431277 }
13441278
1345- public void doTestStringSortOptimizationDisabled (DirectoryReader reader ) throws IOException {
1346- SortField sortField =
1347- KeywordField .newSortField (
1348- "my_field" , false , SortedSetSelector .Type .MIN , SortField .STRING_LAST );
1349- sortField .setOptimizeSortWithIndexedData (false );
1350-
1351- Sort sort = new Sort (sortField );
1352- final int numDocs = reader .numDocs ();
1353- final int numHits = 5 ;
1354-
1355- TopDocs topDocs = assertSearchHits (reader , sort , numHits , null );
1356- assertEquals (numDocs , topDocs .totalHits .value ());
1357- }
1358-
13591279 private TopDocs assertSort (DirectoryReader reader , Sort sort , int n , FieldDoc after )
13601280 throws IOException {
13611281 TopDocs topDocs = assertSearchHits (reader , sort , n , after );
0 commit comments