diff --git a/src/Kentico.Xperience.Lucene.Core/Indexing/DefaultLuceneClient.cs b/src/Kentico.Xperience.Lucene.Core/Indexing/DefaultLuceneClient.cs index 8af4727..11e5b80 100644 --- a/src/Kentico.Xperience.Lucene.Core/Indexing/DefaultLuceneClient.cs +++ b/src/Kentico.Xperience.Lucene.Core/Indexing/DefaultLuceneClient.cs @@ -238,9 +238,18 @@ private Task UpsertRecordsInternal(IEnumerable documents, string // delete old document, there is no upsert nor update in Lucene string? id = document.Get(nameof(IIndexEventItemModel.ItemGuid)); - if (id is not null) + string? language = document.Get(nameof(IIndexEventItemModel.LanguageName)); + if (id is not null && language is not null) { - writer.DeleteDocuments(new Term(nameof(IIndexEventItemModel.ItemGuid), id)); + // for now all changes are creates, update to be done later + // delete old document, there is no upsert nor update in Lucene + var multiTermQuery = new BooleanQuery + { + { new TermQuery(new Term(nameof(IIndexEventItemModel.ItemGuid), id)), Occur.MUST }, + { new TermQuery(new Term(nameof(IIndexEventItemModel.LanguageName), language)), Occur.MUST } + }; + + writer.DeleteDocuments(multiTermQuery); } // add new one @@ -273,11 +282,18 @@ private Task UpsertRecordsInternal(IEnumerable documents, string foreach (var document in documents) { string? id = document.Get(nameof(IIndexEventItemModel.ItemGuid)); - if (id is not null) + string? language = document.Get(nameof(IIndexEventItemModel.LanguageName)); + if (id is not null && language is not null) { // for now all changes are creates, update to be done later // delete old document, there is no upsert nor update in Lucene - writer.DeleteDocuments(new Term(nameof(IIndexEventItemModel.ItemGuid), id)); + var multiTermQuery = new BooleanQuery + { + { new TermQuery(new Term(nameof(IIndexEventItemModel.ItemGuid), id)), Occur.MUST }, + { new TermQuery(new Term(nameof(IIndexEventItemModel.LanguageName), language)), Occur.MUST } + }; + + writer.DeleteDocuments(multiTermQuery); } // add new one #pragma warning disable S2589 // Boolean expressions should not be gratuitous