@@ -177,9 +177,8 @@ public void visit(DocIdSetIterator iterator) throws IOException {
177
177
178
178
@ Override
179
179
public void visit (IntsRef ref ) {
180
- for (int i = 0 ; i < ref .length ; i ++) {
181
- adder .add (ref .ints [ref .offset + i ]);
182
- }
180
+ adder .add (ref );
181
+ docCount [0 ] += ref .length ;
183
182
}
184
183
185
184
@ Override
@@ -293,63 +292,45 @@ public void intersectLeft(PointValues.IntersectVisitor visitor, PointValues.Poin
293
292
}
294
293
}
295
294
296
- // custom intersect visitor to walk the right of tree
295
+ // custom intersect visitor to walk the right of tree (from rightmost leaf going left)
297
296
public void intersectRight (PointValues .IntersectVisitor visitor , PointValues .PointTree pointTree , long [] docCount )
298
297
throws IOException {
299
298
PointValues .Relation r = visitor .compare (pointTree .getMinPackedValue (), pointTree .getMaxPackedValue ());
300
299
if (docCount [0 ] >= size ) {
301
300
return ;
302
301
}
303
302
switch (r ) {
304
- case CELL_OUTSIDE_QUERY :
305
- // This cell is fully outside the query shape: stop recursing
306
- break ;
307
-
308
303
case CELL_INSIDE_QUERY :
309
- // If the cell is fully inside, we keep moving right as long as the point tree size is over our size requirement
310
- if (pointTree .size () > size && docCount [0 ] < size && moveRight (pointTree )) {
304
+ case CELL_CROSSES_QUERY :
305
+ if (pointTree .moveToChild () && docCount [0 ] < size ) {
306
+ while (pointTree .moveToSibling ()) {
307
+ }
308
+
311
309
intersectRight (visitor , pointTree , docCount );
310
+
312
311
pointTree .moveToParent ();
313
- }
314
- // if point tree size is no longer over, we have to go back one level where it still was over and the intersect left
315
- else if (pointTree .size () <= size && docCount [0 ] < size ) {
316
- pointTree .moveToParent ();
317
- intersectLeft (visitor , pointTree , docCount );
318
- }
319
- // if we've reached leaf, it means out size is under the size of the leaf, we can just collect all docIDs
320
- else {
321
- // Leaf node; scan and filter all points in this block:
312
+
322
313
if (docCount [0 ] < size ) {
323
- pointTree .visitDocIDs (visitor );
314
+ pointTree .moveToChild ();
315
+ intersectRight (visitor , pointTree , docCount );
316
+ pointTree .moveToParent ();
324
317
}
325
- }
326
- break ;
327
- case CELL_CROSSES_QUERY :
328
- // If the cell is fully inside, we keep moving right as long as the point tree size is over our size requirement
329
- if (pointTree .size () > size && docCount [0 ] < size && moveRight (pointTree )) {
330
- intersectRight (visitor , pointTree , docCount );
331
- pointTree .moveToParent ();
332
- }
333
- // if point tree size is no longer over, we have to go back one level where it still was over and the intersect left
334
- else if (pointTree .size () <= size && docCount [0 ] < size ) {
335
- pointTree .moveToParent ();
336
- intersectLeft (visitor , pointTree , docCount );
337
- }
338
- // if we've reached leaf, it means out size is under the size of the leaf, we can just collect all doc values
339
- else {
340
- // Leaf node; scan and filter all points in this block:
318
+ } else {
341
319
if (docCount [0 ] < size ) {
342
- pointTree .visitDocValues (visitor );
320
+ if (r == PointValues .Relation .CELL_INSIDE_QUERY ) {
321
+ pointTree .visitDocIDs (visitor );
322
+ } else {
323
+ pointTree .visitDocValues (visitor );
324
+ }
343
325
}
344
326
}
345
327
break ;
328
+ case CELL_OUTSIDE_QUERY :
329
+ break ;
346
330
default :
347
331
throw new IllegalArgumentException ("Unreachable code" );
348
332
}
349
- }
350
333
351
- public boolean moveRight (PointValues .PointTree pointTree ) throws IOException {
352
- return pointTree .moveToChild () && pointTree .moveToSibling ();
353
334
}
354
335
355
336
@ Override
0 commit comments