@@ -146,6 +146,32 @@ private boolean matches(byte[] packedValue) {
146
146
return true ;
147
147
}
148
148
149
+ private PointValues .MatchState matchWithState (byte [] packedValue , int sortedDim ) {
150
+ int offset = sortedDim * bytesPerDim ;
151
+ if (comparator .compare (packedValue , offset , lowerPoint , offset ) < 0 ) {
152
+ // Doc's value is too low, in sorted dimension
153
+ return PointValues .MatchState .LOW ;
154
+ }
155
+ if (comparator .compare (packedValue , offset , upperPoint , offset ) > 0 ) {
156
+ // Doc's value is too high, in sorted dimension, early terminate.
157
+ return PointValues .MatchState .HIGH_IN_SORTED_DIM ;
158
+ }
159
+
160
+ for (int dim = 0 ; dim < numDims ; dim ++) {
161
+ if (dim == sortedDim ) continue ;
162
+ offset = dim * bytesPerDim ;
163
+ if (comparator .compare (packedValue , offset , lowerPoint , offset ) < 0 ) {
164
+ // Doc's value is too low, in non-sorted dimension
165
+ return PointValues .MatchState .LOW ;
166
+ }
167
+ if (comparator .compare (packedValue , offset , upperPoint , offset ) > 0 ) {
168
+ // Doc's value is too high, in non-sorted dimension
169
+ return PointValues .MatchState .HIGH_IN_NON_SORTED_DIM ;
170
+ }
171
+ }
172
+ return PointValues .MatchState .MATCH ;
173
+ }
174
+
149
175
private IntersectVisitor getIntersectVisitor (DocIdSetBuilder result ) {
150
176
return new IntersectVisitor () {
151
177
@@ -178,13 +204,37 @@ public void visit(int docID, byte[] packedValue) {
178
204
}
179
205
}
180
206
207
+ @ Override
208
+ public PointValues .VisitState visitWithSortedDim (
209
+ int docID , byte [] packedValue , int sortedDim ) {
210
+ PointValues .MatchState matchState = matchWithState (packedValue , sortedDim );
211
+ if (matchState == PointValues .MatchState .MATCH ) {
212
+ visit (docID );
213
+ } else if (matchState == PointValues .MatchState .HIGH_IN_SORTED_DIM ) {
214
+ return PointValues .VisitState .TERMINATE ;
215
+ }
216
+ return PointValues .VisitState .CONTINUE ;
217
+ }
218
+
181
219
@ Override
182
220
public void visit (DocIdSetIterator iterator , byte [] packedValue ) throws IOException {
183
221
if (matches (packedValue )) {
184
222
adder .add (iterator );
185
223
}
186
224
}
187
225
226
+ @ Override
227
+ public PointValues .VisitState visitWithSortedDim (
228
+ DocIdSetIterator iterator , byte [] packedValue , int sortedDim ) throws IOException {
229
+ PointValues .MatchState matchState = matchWithState (packedValue , sortedDim );
230
+ if (matchState == PointValues .MatchState .MATCH ) {
231
+ adder .add (iterator );
232
+ } else if (matchState == PointValues .MatchState .HIGH_IN_SORTED_DIM ) {
233
+ return PointValues .VisitState .TERMINATE ;
234
+ }
235
+ return PointValues .VisitState .CONTINUE ;
236
+ }
237
+
188
238
@ Override
189
239
public Relation compare (byte [] minPackedValue , byte [] maxPackedValue ) {
190
240
return relate (minPackedValue , maxPackedValue );
@@ -223,13 +273,39 @@ public void visit(int docID, byte[] packedValue) {
223
273
}
224
274
}
225
275
276
+ @ Override
277
+ public PointValues .VisitState visitWithSortedDim (
278
+ int docID , byte [] packedValue , int sortedDim ) {
279
+ PointValues .MatchState matchState = matchWithState (packedValue , sortedDim );
280
+ if (matchState == PointValues .MatchState .HIGH_IN_SORTED_DIM ) {
281
+ // Leave this docID in remaining docs to visit.
282
+ return PointValues .VisitState .MATCH_REMAINING ;
283
+ } else if (matchState != PointValues .MatchState .MATCH ) {
284
+ visit (docID );
285
+ }
286
+ return PointValues .VisitState .CONTINUE ;
287
+ }
288
+
226
289
@ Override
227
290
public void visit (DocIdSetIterator iterator , byte [] packedValue ) throws IOException {
228
291
if (matches (packedValue ) == false ) {
229
292
visit (iterator );
230
293
}
231
294
}
232
295
296
+ @ Override
297
+ public PointValues .VisitState visitWithSortedDim (
298
+ DocIdSetIterator iterator , byte [] packedValue , int sortedDim ) throws IOException {
299
+ PointValues .MatchState matchState = matchWithState (packedValue , sortedDim );
300
+ if (matchState == PointValues .MatchState .HIGH_IN_SORTED_DIM ) {
301
+ // Leave this iterator in remaining docs to visit.
302
+ return PointValues .VisitState .MATCH_REMAINING ;
303
+ } else if (matchState != PointValues .MatchState .MATCH ) {
304
+ visit (iterator );
305
+ }
306
+ return PointValues .VisitState .CONTINUE ;
307
+ }
308
+
233
309
@ Override
234
310
public Relation compare (byte [] minPackedValue , byte [] maxPackedValue ) {
235
311
Relation relation = relate (minPackedValue , maxPackedValue );
@@ -401,6 +477,18 @@ public void visit(int docID, byte[] packedValue) {
401
477
}
402
478
}
403
479
480
+ @ Override
481
+ public PointValues .VisitState visitWithSortedDim (
482
+ int docID , byte [] packedValue , int sortedDim ) throws IOException {
483
+ PointValues .MatchState matchState = matchWithState (packedValue , sortedDim );
484
+ if (matchState == PointValues .MatchState .MATCH ) {
485
+ matchingNodeCount [0 ]++;
486
+ } else if (matchState == PointValues .MatchState .HIGH_IN_SORTED_DIM ) {
487
+ return PointValues .VisitState .TERMINATE ;
488
+ }
489
+ return PointValues .VisitState .CONTINUE ;
490
+ }
491
+
404
492
@ Override
405
493
public Relation compare (byte [] minPackedValue , byte [] maxPackedValue ) {
406
494
return nodeComparator .apply (minPackedValue , maxPackedValue );
0 commit comments