@@ -161,11 +161,6 @@ public void grow(int count) {
161
161
162
162
@ Override
163
163
public void visit (int docID ) {
164
- // it is possible that size < 1024 and docCount < size but we will continue to count through all the 1024 docs
165
- // and collect less, but it won't hurt performance
166
- if (docCount [0 ] >= size ) {
167
- return ;
168
- }
169
164
adder .add (docID );
170
165
docCount [0 ]++;
171
166
}
@@ -177,9 +172,8 @@ public void visit(DocIdSetIterator iterator) throws IOException {
177
172
178
173
@ Override
179
174
public void visit (IntsRef ref ) {
180
- for (int i = 0 ; i < ref .length ; i ++) {
181
- adder .add (ref .ints [ref .offset + i ]);
182
- }
175
+ adder .add (ref );
176
+ docCount [0 ] += ref .length ;
183
177
}
184
178
185
179
@ Override
@@ -248,10 +242,10 @@ private void intersectRight(PointValues.PointTree pointTree, PointValues.Interse
248
242
// custom intersect visitor to walk the left of the tree
249
243
public void intersectLeft (PointValues .IntersectVisitor visitor , PointValues .PointTree pointTree , long [] docCount )
250
244
throws IOException {
251
- PointValues .Relation r = visitor .compare (pointTree .getMinPackedValue (), pointTree .getMaxPackedValue ());
252
245
if (docCount [0 ] >= size ) {
253
246
return ;
254
247
}
248
+ PointValues .Relation r = visitor .compare (pointTree .getMinPackedValue (), pointTree .getMaxPackedValue ());
255
249
switch (r ) {
256
250
case CELL_OUTSIDE_QUERY :
257
251
// This cell is fully outside the query shape: stop recursing
@@ -293,63 +287,45 @@ public void intersectLeft(PointValues.IntersectVisitor visitor, PointValues.Poin
293
287
}
294
288
}
295
289
296
- // custom intersect visitor to walk the right of tree
290
+ // custom intersect visitor to walk the right of tree (from rightmost leaf going left)
297
291
public void intersectRight (PointValues .IntersectVisitor visitor , PointValues .PointTree pointTree , long [] docCount )
298
292
throws IOException {
299
- PointValues .Relation r = visitor .compare (pointTree .getMinPackedValue (), pointTree .getMaxPackedValue ());
300
293
if (docCount [0 ] >= size ) {
301
294
return ;
302
295
}
296
+ PointValues .Relation r = visitor .compare (pointTree .getMinPackedValue (), pointTree .getMaxPackedValue ());
303
297
switch (r ) {
304
- case CELL_OUTSIDE_QUERY :
305
- // This cell is fully outside the query shape: stop recursing
306
- break ;
307
-
308
298
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 )) {
299
+ case CELL_CROSSES_QUERY :
300
+ if (pointTree .moveToChild () && docCount [0 ] < size ) {
301
+ while (pointTree .moveToSibling ()) {
302
+ }
303
+
311
304
intersectRight (visitor , pointTree , docCount );
305
+
312
306
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:
307
+
322
308
if (docCount [0 ] < size ) {
323
- pointTree .visitDocIDs (visitor );
309
+ pointTree .moveToChild ();
310
+ intersectRight (visitor , pointTree , docCount );
311
+ pointTree .moveToParent ();
324
312
}
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:
313
+ } else {
341
314
if (docCount [0 ] < size ) {
342
- pointTree .visitDocValues (visitor );
315
+ if (r == PointValues .Relation .CELL_INSIDE_QUERY ) {
316
+ pointTree .visitDocIDs (visitor );
317
+ } else {
318
+ pointTree .visitDocValues (visitor );
319
+ }
343
320
}
344
321
}
345
322
break ;
323
+ case CELL_OUTSIDE_QUERY :
324
+ break ;
346
325
default :
347
326
throw new IllegalArgumentException ("Unreachable code" );
348
327
}
349
- }
350
328
351
- public boolean moveRight (PointValues .PointTree pointTree ) throws IOException {
352
- return pointTree .moveToChild () && pointTree .moveToSibling ();
353
329
}
354
330
355
331
@ Override
0 commit comments