Skip to content

Commit a148a69

Browse files
committed
Implement visit with sorted dim.
1 parent 107af45 commit a148a69

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java

+88
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,32 @@ private boolean matches(byte[] packedValue) {
146146
return true;
147147
}
148148

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+
149175
private IntersectVisitor getIntersectVisitor(DocIdSetBuilder result) {
150176
return new IntersectVisitor() {
151177

@@ -178,13 +204,37 @@ public void visit(int docID, byte[] packedValue) {
178204
}
179205
}
180206

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+
181219
@Override
182220
public void visit(DocIdSetIterator iterator, byte[] packedValue) throws IOException {
183221
if (matches(packedValue)) {
184222
adder.add(iterator);
185223
}
186224
}
187225

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+
188238
@Override
189239
public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
190240
return relate(minPackedValue, maxPackedValue);
@@ -223,13 +273,39 @@ public void visit(int docID, byte[] packedValue) {
223273
}
224274
}
225275

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+
226289
@Override
227290
public void visit(DocIdSetIterator iterator, byte[] packedValue) throws IOException {
228291
if (matches(packedValue) == false) {
229292
visit(iterator);
230293
}
231294
}
232295

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+
233309
@Override
234310
public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
235311
Relation relation = relate(minPackedValue, maxPackedValue);
@@ -401,6 +477,18 @@ public void visit(int docID, byte[] packedValue) {
401477
}
402478
}
403479

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+
404492
@Override
405493
public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
406494
return nodeComparator.apply(minPackedValue, maxPackedValue);

0 commit comments

Comments
 (0)