@@ -395,7 +395,6 @@ public void testApproximateRangeShortCircuitDescSort() throws IOException {
395
395
long [] scratch = new long [dims ];
396
396
int numPoints = 1000 ;
397
397
for (int i = 0 ; i < numPoints ; i ++) {
398
- Document doc = new Document ();
399
398
for (int v = 0 ; v < dims ; v ++) {
400
399
scratch [v ] = i ;
401
400
}
@@ -487,7 +486,6 @@ public void testIntersectRightCellInsideQueryLeaf() throws IOException {
487
486
long [] scratch = new long [dims ];
488
487
// Create a smaller dataset that will result in leaf nodes that are completely inside the query range
489
488
for (int i = 900 ; i <= 999 ; i ++) {
490
- Document doc = new Document ();
491
489
scratch [0 ] = i ;
492
490
iw .addDocument (asList (new LongPoint ("point" , scratch [0 ]), new NumericDocValuesField ("point" , scratch [0 ])));
493
491
}
@@ -530,13 +528,11 @@ public void testIntersectRightCellOutsideQuery() throws IOException {
530
528
// Create documents in two separate ranges to ensure some cells are outside query
531
529
// Range 1: 0-99
532
530
for (int i = 0 ; i < 100 ; i ++) {
533
- Document doc = new Document ();
534
531
scratch [0 ] = i ;
535
532
iw .addDocument (asList (new LongPoint ("point" , scratch [0 ]), new NumericDocValuesField ("point" , scratch [0 ])));
536
533
}
537
534
// Range 2: 500-599 (gap ensures some tree nodes will be completely outside query)
538
535
for (int i = 500 ; i < 600 ; i ++) {
539
- Document doc = new Document ();
540
536
scratch [0 ] = i ;
541
537
iw .addDocument (asList (new LongPoint ("point" , scratch [0 ]), new NumericDocValuesField ("point" , scratch [0 ])));
542
538
}
@@ -577,7 +573,6 @@ public void testIntersectRightCellCrossesQuery() throws IOException {
577
573
long [] scratch = new long [dims ];
578
574
// Create documents that will result in cells that cross the query boundary
579
575
for (int i = 0 ; i < 1000 ; i ++) {
580
- Document doc = new Document ();
581
576
scratch [0 ] = i ;
582
577
iw .addDocument (asList (new LongPoint ("point" , scratch [0 ]), new NumericDocValuesField ("point" , scratch [0 ])));
583
578
}
@@ -611,4 +606,45 @@ public void testIntersectRightCellCrossesQuery() throws IOException {
611
606
}
612
607
}
613
608
}
609
+
610
+ // Test to specifically cover the single child case in intersectRight
611
+ public void testIntersectRightSingleChildNode () throws IOException {
612
+ try (Directory directory = newDirectory ()) {
613
+ try (RandomIndexWriter iw = new RandomIndexWriter (random (), directory , new WhitespaceAnalyzer ())) {
614
+ int dims = 1 ;
615
+ long [] scratch = new long [dims ];
616
+
617
+ for (int i = 0 ; i < 100 ; i ++) {
618
+ scratch [0 ] = 1000L ;
619
+ iw .addDocument (asList (new LongPoint ("point" , scratch [0 ]), new NumericDocValuesField ("point" , scratch [0 ])));
620
+ }
621
+ scratch [0 ] = 987654321L ;
622
+ iw .addDocument (asList (new LongPoint ("point" , scratch [0 ]), new NumericDocValuesField ("point" , scratch [0 ])));
623
+
624
+ iw .flush ();
625
+ iw .forceMerge (1 );
626
+
627
+ try (IndexReader reader = iw .getReader ()) {
628
+ long lower = 500L ;
629
+ long upper = 999999999L ;
630
+
631
+ ApproximatePointRangeQuery query = new ApproximatePointRangeQuery (
632
+ "point" ,
633
+ pack (lower ).bytes ,
634
+ pack (upper ).bytes ,
635
+ dims ,
636
+ 50 ,
637
+ SortOrder .DESC ,
638
+ ApproximatePointRangeQuery .LONG_FORMAT
639
+ );
640
+
641
+ IndexSearcher searcher = new IndexSearcher (reader );
642
+ Sort sort = new Sort (new SortField ("point" , SortField .Type .LONG , true ));
643
+ TopDocs topDocs = searcher .search (query , 50 , sort );
644
+
645
+ assertEquals ("Should return exactly 50 documents" , 50 , topDocs .scoreDocs .length );
646
+ }
647
+ }
648
+ }
649
+ }
614
650
}
0 commit comments