Skip to content

Commit

Permalink
sepinf-inc#2253: Handle double[] as extraAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
aberenguel committed Jun 28, 2024
1 parent 5cbc495 commit d18ebde
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion iped-engine/src/main/java/iped/engine/task/index/IndexItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ public static void saveMetadataTypes(File confDir) throws IOException {
UTF8Properties props = new UTF8Properties();
for (Object o : typesMap.entrySet().toArray()) {
Entry<String, Class<?>> e = (Entry<String, Class<?>>) o;
props.setProperty(e.getKey(), e.getValue().getCanonicalName());
if (e.getValue().isArray()) {
props.setProperty(e.getKey(), e.getValue().getName());
} else {
props.setProperty(e.getKey(), e.getValue().getCanonicalName());
}
}
props.store(metadataTypesFile);
IOUtils.fsync(metadataTypesFile.toPath(), false);
Expand Down Expand Up @@ -612,6 +616,7 @@ private static void addExtraAttributeToDoc(Document doc, String key, Object oVal
doc.add(new SortedNumericDocValuesField(key, NumericUtils.doubleToSortableLong((Double) oValue)));

} else if (oValue instanceof NDArray) {
System.err.println("NDArray ====> " + ((NDArray)oValue).getData());
float[] floatArray = convNDArrayToFloatArray((NDArray) oValue);
byte[] byteArray = convFloatArrayToByteArray(floatArray);
int suffix = 0;
Expand All @@ -624,6 +629,18 @@ private static void addExtraAttributeToDoc(Document doc, String key, Object oVal
doc.add(new StoredField(key, byteArray));
doc.add(new KnnVectorField(knnKey, floatArray));

} else if (oValue instanceof double[]) {
float[] floatArray = convDoubleToFloatArray((double[]) oValue);
byte[] byteArray = convFloatArrayToByteArray(floatArray);
int suffix = 0;
// KnnVectorField is not multivalued, must use other key if it exists
String knnKey = key;
while (doc.getField(knnKey) != null) {
knnKey = key + (++suffix);
}
doc.add(new SortedSetDocValuesField(key, new BytesRef(byteArray)));
doc.add(new StoredField(key, byteArray));
doc.add(new KnnVectorField(knnKey, floatArray));
} else {
// value is typed as string
String value = oValue.toString();
Expand Down

0 comments on commit d18ebde

Please sign in to comment.