Skip to content

Commit

Permalink
fixing for backport
Browse files Browse the repository at this point in the history
  • Loading branch information
benwtrent committed Nov 8, 2024
1 parent ef6703c commit 76574f8
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.apache.lucene.index.ByteVectorValues;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.FloatVectorValues;
import org.apache.lucene.index.KnnVectorValues;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.fielddata.FormattedDocValues;
Expand Down Expand Up @@ -92,13 +92,11 @@ public FormattedDocValues getFormattedValues(DocValueFormat format) {
case BYTE, BIT -> new FormattedDocValues() {
private byte[] vector = new byte[dims];
private ByteVectorValues byteVectorValues; // use when indexed
private KnnVectorValues.DocIndexIterator iterator; // use when indexed
private BinaryDocValues binary; // use when not indexed
{
try {
if (indexed) {
byteVectorValues = reader.getByteVectorValues(field);
iterator = (byteVectorValues == null) ? null : byteVectorValues.iterator();
} else {
binary = DocValues.getBinary(reader, field);
}
Expand All @@ -111,10 +109,10 @@ public FormattedDocValues getFormattedValues(DocValueFormat format) {
@Override
public boolean advanceExact(int docId) throws IOException {
if (indexed) {
if (iteratorAdvanceExact(iterator, docId) == false) {
if (iteratorAdvanceExact(byteVectorValues, docId) == false) {
return false;
}
vector = byteVectorValues.vectorValue(iterator.index());
vector = byteVectorValues.vectorValue();
} else {
if (binary == null || binary.advanceExact(docId) == false) {
return false;
Expand All @@ -141,13 +139,11 @@ public Object nextValue() {
case FLOAT -> new FormattedDocValues() {
float[] vector = new float[dims];
private FloatVectorValues floatVectorValues; // use when indexed
private KnnVectorValues.DocIndexIterator iterator; // use when indexed
private BinaryDocValues binary; // use when not indexed
{
try {
if (indexed) {
floatVectorValues = reader.getFloatVectorValues(field);
iterator = (floatVectorValues == null) ? null : floatVectorValues.iterator();
} else {
binary = DocValues.getBinary(reader, field);
}
Expand All @@ -160,10 +156,10 @@ public Object nextValue() {
@Override
public boolean advanceExact(int docId) throws IOException {
if (indexed) {
if (iteratorAdvanceExact(iterator, docId) == false) {
if (iteratorAdvanceExact(floatVectorValues, docId) == false) {
return false;
}
vector = floatVectorValues.vectorValue(iterator.index());
vector = floatVectorValues.vectorValue();
} else {
if (binary == null || binary.advanceExact(docId) == false) {
return false;
Expand All @@ -187,7 +183,7 @@ public Object nextValue() {
};
}

private static boolean iteratorAdvanceExact(KnnVectorValues.DocIndexIterator iterator, int docId) throws IOException {
private static boolean iteratorAdvanceExact(DocIdSetIterator iterator, int docId) throws IOException {
if (iterator == null) return false;
int currentDoc = iterator.docID();
if (currentDoc == NO_MORE_DOCS || docId < currentDoc) {
Expand Down

0 comments on commit 76574f8

Please sign in to comment.