Skip to content

Commit 0948edf

Browse files
committed
Fix compilation.
1 parent bb071f7 commit 0948edf

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/main/perf/LineFileDocs.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.apache.lucene.document.FieldType;
5656
import org.apache.lucene.document.IntField;
5757
import org.apache.lucene.document.IntPoint;
58+
import org.apache.lucene.document.KnnByteVectorField;
5859
import org.apache.lucene.document.KnnVectorField;
5960
import org.apache.lucene.document.LongField;
6061
import org.apache.lucene.document.LongPoint;
@@ -364,7 +365,8 @@ public static final class DocState {
364365
final Field timeSec;
365366
// Necessary for "old style" wiki line files:
366367
final SimpleDateFormat dateParser = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", Locale.US);
367-
final KnnVectorField vectorField;
368+
final KnnVectorField floatVectorField;
369+
final KnnByteVectorField byteVectorField;
368370

369371
// For just y/m/day:
370372
//final SimpleDateFormat dateParser = new SimpleDateFormat("y/M/d", Locale.US);
@@ -452,14 +454,18 @@ public static final class DocState {
452454
doc.add(timeSec);
453455

454456
if (vectorDimension > 0) {
455-
// create a throwaway vector so the field's type gets the proper dimension and similarity
456-
vectorField = switch (vectorEncoding) {
457-
case BYTE -> new KnnVectorField("vector", new BytesRef(new byte[vectorDimension]), VectorSimilarityFunction.DOT_PRODUCT);
458-
case FLOAT32 -> new KnnVectorField("vector", new float[vectorDimension], VectorSimilarityFunction.DOT_PRODUCT);
459-
};
460-
doc.add(vectorField);
457+
if (vectorEncoding == VectorEncoding.FLOAT32) {
458+
floatVectorField = new KnnVectorField("vector", new float[vectorDimension], VectorSimilarityFunction.DOT_PRODUCT);
459+
doc.add(floatVectorField);
460+
byteVectorField = null;
461+
} else {
462+
byteVectorField = new KnnByteVectorField("vector", new BytesRef(new byte[vectorDimension]), VectorSimilarityFunction.DOT_PRODUCT);
463+
doc.add(byteVectorField);
464+
floatVectorField = null;
465+
}
461466
} else {
462-
vectorField = null;
467+
floatVectorField = null;
468+
byteVectorField = null;
463469
}
464470
}
465471
}
@@ -616,7 +622,11 @@ public Document nextDoc(DocState doc, boolean expected) throws IOException {
616622
line = null;
617623

618624
if (lfd.vector != null) {
619-
lfd.getVector(doc.vectorField.vectorValue());
625+
if (doc.floatVectorField != null) {
626+
lfd.getVector(doc.floatVectorField.vectorValue());
627+
} else {
628+
lfd.getVector(doc.byteVectorField.vectorValue().bytes);
629+
}
620630
}
621631

622632
} else {
@@ -672,8 +682,10 @@ public Document nextDoc(DocState doc, boolean expected) throws IOException {
672682
doc.dateCal.setTime(date);
673683
msecSinceEpoch = doc.dateCal.getTimeInMillis();
674684
timeSec = doc.dateCal.get(Calendar.HOUR_OF_DAY)*3600 + doc.dateCal.get(Calendar.MINUTE)*60 + doc.dateCal.get(Calendar.SECOND);
675-
if (doc.vectorField != null) {
676-
doc.vectorField.setVectorValue((float[]) lfd.vector.array());
685+
if (doc.floatVectorField != null) {
686+
doc.floatVectorField.setVectorValue((float[]) lfd.vector.array());
687+
} else if (doc.byteVectorField != null) {
688+
doc.byteVectorField.setVectorValue(new BytesRef((byte[]) lfd.vector.array()));
677689
}
678690
}
679691

0 commit comments

Comments
 (0)