From e76b712ccaf96ea0c3fef61655474e235e93019a Mon Sep 17 00:00:00 2001 From: kapustb Date: Fri, 20 Oct 2023 12:06:11 +0200 Subject: [PATCH] Indexing delete node --- src/AlgoliaSearchModule.cs | 13 +++++++++++-- .../Implementations/DefaultAlgoliaTaskLogger.cs | 7 ++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/AlgoliaSearchModule.cs b/src/AlgoliaSearchModule.cs index c4f6726..a92214b 100644 --- a/src/AlgoliaSearchModule.cs +++ b/src/AlgoliaSearchModule.cs @@ -60,8 +60,8 @@ protected override void OnInit() DocumentEvents.Delete.Before += HandleDocumentEvent; DocumentEvents.Update.Before += HandleDocumentEvent; - DocumentEvents.Update.After += ForceMoveUpdate; - DocumentEvents.Delete.After += ForceMoveUpdate; + DocumentEvents.Update.Before += ForceMoveUpdate; + DocumentEvents.Delete.Before += ForceDelete; DocumentEvents.Insert.After += HandleDocumentEvent; WorkflowEvents.Publish.After += HandleWorkflowEvent; WorkflowEvents.Archive.After += HandleWorkflowEvent; @@ -120,5 +120,14 @@ private void ForceMoveUpdate(object sender, DocumentEventArgs e) algoliaTaskLogger.HandleEventAfter(e.Node, e.CurrentHandler.Name); } } + + private void ForceDelete(object sender, DocumentEventArgs e) + { + if (!EventShouldContinue(e.Node)) + { + return; + } + algoliaTaskLogger.HandleEventAfter(e.Node, e.CurrentHandler.Name); + } } } \ No newline at end of file diff --git a/src/Services/Implementations/DefaultAlgoliaTaskLogger.cs b/src/Services/Implementations/DefaultAlgoliaTaskLogger.cs index be03c39..194cbc6 100644 --- a/src/Services/Implementations/DefaultAlgoliaTaskLogger.cs +++ b/src/Services/Implementations/DefaultAlgoliaTaskLogger.cs @@ -16,7 +16,6 @@ internal class DefaultAlgoliaTaskLogger : IAlgoliaTaskLogger { private readonly IEventLogService eventLogService; - public DefaultAlgoliaTaskLogger(IEventLogService eventLogService) { this.eventLogService = eventLogService; } @@ -53,6 +52,12 @@ public void HandleEvent(TreeNode node, string eventName) public void HandleEventAfter(TreeNode node, string eventName) { + var treeProvider = new TreeProvider(); + if (eventName != DocumentEvents.Delete.Name) + { + node = treeProvider.SelectSingleDocument(node.DocumentID, coupledData: true); + } + foreach (var indexName in IndexStore.Instance.GetAll().Select(index => index.IndexName)) { if (!node.IsIndexedByIndex(indexName))