diff --git a/src/main/java/it/cavallium/dbengine/client/Indicizer.java b/src/main/java/it/cavallium/dbengine/client/Indicizer.java index d92482c..7fdd0a2 100644 --- a/src/main/java/it/cavallium/dbengine/client/Indicizer.java +++ b/src/main/java/it/cavallium/dbengine/client/Indicizer.java @@ -1,6 +1,7 @@ package it.cavallium.dbengine.client; import it.cavallium.dbengine.database.LLIndexRequest; +import it.cavallium.dbengine.database.LLSoftUpdateDocument; import it.cavallium.dbengine.database.LLUpdateDocument; import it.cavallium.dbengine.database.LLTerm; import it.cavallium.dbengine.database.LLUpdateFields; @@ -24,6 +25,8 @@ public abstract class Indicizer { return new LLUpdateDocument(updateFields.items()); } else if (req instanceof LLUpdateDocument updateDocument) { return updateDocument; + } else if (req instanceof LLSoftUpdateDocument softUpdateDocument) { + return new LLUpdateDocument(softUpdateDocument.items()); } else { throw new UnsupportedOperationException("Unexpected request type: " + req); } diff --git a/src/main/java/it/cavallium/dbengine/database/LLIndexRequest.java b/src/main/java/it/cavallium/dbengine/database/LLIndexRequest.java index 6876567..4a8f884 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLIndexRequest.java +++ b/src/main/java/it/cavallium/dbengine/database/LLIndexRequest.java @@ -1,3 +1,3 @@ package it.cavallium.dbengine.database; -public sealed interface LLIndexRequest permits LLUpdateDocument, LLUpdateFields {} +public sealed interface LLIndexRequest permits LLSoftUpdateDocument, LLUpdateDocument, LLUpdateFields {} diff --git a/src/main/java/it/cavallium/dbengine/database/LLSoftUpdateDocument.java b/src/main/java/it/cavallium/dbengine/database/LLSoftUpdateDocument.java new file mode 100644 index 0000000..d381e76 --- /dev/null +++ b/src/main/java/it/cavallium/dbengine/database/LLSoftUpdateDocument.java @@ -0,0 +1,3 @@ +package it.cavallium.dbengine.database; + +public record LLSoftUpdateDocument(LLItem[] items, LLItem[] softDeleteItems) implements LLIndexRequest {} diff --git a/src/main/java/it/cavallium/dbengine/database/LLUtils.java b/src/main/java/it/cavallium/dbengine/database/LLUtils.java index 86d396b..be368a3 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLUtils.java +++ b/src/main/java/it/cavallium/dbengine/database/LLUtils.java @@ -127,8 +127,12 @@ public class LLUtils { } public static Document toDocument(LLUpdateDocument document) { + return toDocument(document.items()); + } + + public static Document toDocument(LLItem[] document) { Document d = new Document(); - for (LLItem item : document.items()) { + for (LLItem item : document) { d.add(LLUtils.toField(item)); } return d; diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java index 0d6bec5..839ea5b 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java @@ -12,6 +12,7 @@ import it.cavallium.dbengine.client.LuceneOptions; import it.cavallium.dbengine.client.NRTCachingOptions; import it.cavallium.dbengine.client.query.current.data.QueryParams; import it.cavallium.dbengine.database.LLIndexRequest; +import it.cavallium.dbengine.database.LLSoftUpdateDocument; import it.cavallium.dbengine.database.LLUpdateDocument; import it.cavallium.dbengine.database.LLItem; import it.cavallium.dbengine.database.LLLuceneIndex; @@ -319,6 +320,11 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { .runSafe(() -> { if (request instanceof LLUpdateDocument updateDocument) { indexWriter.updateDocument(LLUtils.toTerm(id), LLUtils.toDocument(updateDocument)); + } else if (request instanceof LLSoftUpdateDocument softUpdateDocument) { + indexWriter.softUpdateDocument(LLUtils.toTerm(id), + LLUtils.toDocument(softUpdateDocument.items()), + LLUtils.toFields(softUpdateDocument.softDeleteItems()) + ); } else if (request instanceof LLUpdateFields updateFields) { indexWriter.updateDocValues(LLUtils.toTerm(id), LLUtils.toFields(updateFields.items())); } else {