Skip to content

Commit

Permalink
fix(DefaultLuceneClient): Differ between languages when deleting docu…
Browse files Browse the repository at this point in the history
…ments for an upsert (#59)
  • Loading branch information
bkapustik authored Jul 12, 2024
1 parent 63c2bdc commit 88e09f3
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/Kentico.Xperience.Lucene.Core/Indexing/DefaultLuceneClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,18 @@ private Task<int> UpsertRecordsInternal(IEnumerable<Document> 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
Expand Down Expand Up @@ -273,11 +282,18 @@ private Task<int> UpsertRecordsInternal(IEnumerable<Document> 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
Expand Down

0 comments on commit 88e09f3

Please sign in to comment.