From 743f7b343a8b6120411e2ee154d099929cb7599a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ante=20Pu=C5=A1i=C4=87?= <ante.pusic@memgraph.io>
Date: Thu, 8 Feb 2024 00:14:06 +0100
Subject: [PATCH] Fix text index logic on label removal

---
 src/query/db_accessor.hpp   | 4 ++++
 src/query/plan/operator.cpp | 2 +-
 src/storage/v2/storage.hpp  | 4 ++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/query/db_accessor.hpp b/src/query/db_accessor.hpp
index 8d610e0f5..9c0293721 100644
--- a/src/query/db_accessor.hpp
+++ b/src/query/db_accessor.hpp
@@ -576,6 +576,10 @@ class DbAccessor final {
 
   void TextIndexUpdateVertex(VertexAccessor *vertex) { accessor_->TextIndexUpdateVertex(&vertex->impl_); }
 
+  void TextIndexUpdateVertex(VertexAccessor *vertex, std::vector<storage::LabelId> removed_labels) {
+    accessor_->TextIndexUpdateVertex(&vertex->impl_, removed_labels);
+  }
+
   std::vector<storage::Gid> TextIndexSearch(std::string index_name, std::string search_query) const {
     return accessor_->TextIndexSearch(index_name, search_query);
   }
diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp
index 7a9ef6228..ccdbb59b6 100644
--- a/src/query/plan/operator.cpp
+++ b/src/query/plan/operator.cpp
@@ -3304,7 +3304,7 @@ bool RemoveLabels::RemoveLabelsCursor::Pull(Frame &frame, ExecutionContext &cont
   }
 
   if (flags::run_time::GetTextSearchEnabled()) {
-    context.db_accessor->TextIndexUpdateVertex(&vertex);
+    context.db_accessor->TextIndexUpdateVertex(&vertex, self_.labels_);
   }
 
   return true;
diff --git a/src/storage/v2/storage.hpp b/src/storage/v2/storage.hpp
index 8e9f14ca5..3fcfff2b4 100644
--- a/src/storage/v2/storage.hpp
+++ b/src/storage/v2/storage.hpp
@@ -239,6 +239,10 @@ class Storage {
       storage_->indices_.text_index_->UpdateNode(vertex->vertex_, storage_, storage_->timestamp_);
     }
 
+    void TextIndexUpdateVertex(VertexAccessor *vertex, std::vector<LabelId> removed_labels) {
+      storage_->indices_.text_index_->UpdateNode(vertex->vertex_, storage_, storage_->timestamp_, removed_labels);
+    }
+
     std::vector<Gid> TextIndexSearch(std::string index_name, std::string search_query) const {
       return storage_->indices_.text_index_->Search(index_name, search_query);
     }