Skip to content

Apache Lucene open-source search software

SlowCompositeCodecReaderWrapper KnnVectorValues handles binary search over array with repeated values

Michael Sokolovf21ec8414c1a
diff --git a/lucene/core/src/java/org/apache/lucene/index/SlowCompositeCodecReaderWrapper.java b/lucene/core/src/java/org/apache/lucene/index/SlowCompositeCodecReaderWrapper.java
index ec2423310d9..69d557d270a 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SlowCompositeCodecReaderWrapper.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SlowCompositeCodecReaderWrapper.java
@@ -898,9 +898,9 @@ final class SlowCompositeCodecReaderWrapper extends CodecReader {
public float[] vectorValue(int ord) throws IOException {
assert ord >= 0 && ord < size;
// We need to implement fully random-access API here in order to support callers like
- // SortingCodecReader that
- // rely on it.
+ // SortingCodecReader that rely on it.
lastSubIndex = findSub(ord, lastSubIndex, starts);
+ assert subs[lastSubIndex].sub != null;
return ((FloatVectorValues) subs[lastSubIndex].sub)
.vectorValue(ord - subs[lastSubIndex].ordStart);
}
@@ -1002,6 +1002,11 @@ final class SlowCompositeCodecReaderWrapper extends CodecReader {
// subtract one since binarySearch returns an *insertion point*
return -2 - pos;
} else {
+ while (pos < starts.length - 1 && starts[pos + 1] == ord) {
+ // Arrays.binarySearch can return any of a sequence of repeated value
+ // but we always want the last one
+ ++pos;
+ }
return pos;
}
}