Skip to content

Commit

Permalink
sepinf-inc#2253: Handle extraAttribute of type double[]
Browse files Browse the repository at this point in the history
  • Loading branch information
aberenguel committed Jun 28, 2024
1 parent bb92776 commit d569ec9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 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 @@ -624,6 +628,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 d569ec9

Please sign in to comment.