diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index ba35e8121..28c64dee6 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -3106,7 +3106,9 @@ bool SetProperties::SetPropertiesCursor::Pull(Frame &frame, ExecutionContext &co } #endif SetPropertiesOnRecord(&lhs.ValueVertex(), rhs, self_.op_, &context, cached_name_id_); - context.db_accessor->TextIndexUpdateVertex(&lhs.ValueVertex()); + if (flags::run_time::GetExperimentalTextSearchEnabled()) { + context.db_accessor->TextIndexUpdateVertex(&lhs.ValueVertex()); + } break; case TypedValue::Type::Edge: #ifdef MG_ENTERPRISE diff --git a/src/query/procedure/mg_procedure_impl.cpp b/src/query/procedure/mg_procedure_impl.cpp index b33377265..087d4e016 100644 --- a/src/query/procedure/mg_procedure_impl.cpp +++ b/src/query/procedure/mg_procedure_impl.cpp @@ -1841,11 +1841,13 @@ mgp_error mgp_vertex_set_property(struct mgp_vertex *v, const char *property_nam std::visit([property_name](auto *impl) { return impl->NameToProperty(property_name); }, v->graph->impl); const auto result = std::visit( - [prop_key, property_value](auto &impl) { - // TODO antepusic also update text index - return impl.SetProperty(prop_key, ToPropertyValue(*property_value)); - }, + [prop_key, property_value](auto &impl) { return impl.SetProperty(prop_key, ToPropertyValue(*property_value)); }, v->impl); + if (memgraph::flags::run_time::GetExperimentalTextSearchEnabled() && !result.HasError()) { + auto v_impl = v->getImpl(); + v->graph->getImpl()->TextIndexUpdateVertex(&v_impl); + } + if (result.HasError()) { switch (result.GetError()) { case memgraph::storage::Error::DELETED_OBJECT: @@ -1902,7 +1904,11 @@ mgp_error mgp_vertex_set_properties(struct mgp_vertex *v, struct mgp_map *proper } const auto result = v->getImpl().UpdateProperties(props); - // TODO antepusic also update text index + if (memgraph::flags::run_time::GetExperimentalTextSearchEnabled() && !result.HasError()) { + auto v_impl = v->getImpl(); + v->graph->getImpl()->TextIndexUpdateVertex(&v_impl); + } + if (result.HasError()) { switch (result.GetError()) { case memgraph::storage::Error::DELETED_OBJECT: @@ -1959,12 +1965,11 @@ mgp_error mgp_vertex_add_label(struct mgp_vertex *v, mgp_label label) { throw ImmutableObjectException{"Cannot add a label to an immutable vertex!"}; } - const auto result = std::visit( - [label_id](auto &impl) { - // TODO antepusic also update text index - return impl.AddLabel(label_id); - }, - v->impl); + const auto result = std::visit([label_id](auto &impl) { return impl.AddLabel(label_id); }, v->impl); + if (memgraph::flags::run_time::GetExperimentalTextSearchEnabled() && !result.HasError()) { + auto v_impl = v->getImpl(); + v->graph->getImpl()->TextIndexUpdateVertex(&v_impl); + } if (result.HasError()) { switch (result.GetError()) { @@ -2006,12 +2011,11 @@ mgp_error mgp_vertex_remove_label(struct mgp_vertex *v, mgp_label label) { if (!MgpVertexIsMutable(*v)) { throw ImmutableObjectException{"Cannot remove a label from an immutable vertex!"}; } - const auto result = std::visit( - [label_id](auto &impl) { - // todo also remove from text index - return impl.RemoveLabel(label_id); - }, - v->impl); + const auto result = std::visit([label_id](auto &impl) { return impl.RemoveLabel(label_id); }, v->impl); + if (memgraph::flags::run_time::GetExperimentalTextSearchEnabled() && !result.HasError()) { + auto v_impl = v->getImpl(); + v->graph->getImpl()->TextIndexUpdateVertex(&v_impl, {label_id}); + } if (result.HasError()) { switch (result.GetError()) { @@ -2981,6 +2985,11 @@ mgp_error mgp_graph_create_vertex(struct mgp_graph *graph, mgp_memory *memory, m } auto *vertex = std::visit( [=](auto *impl) { return NewRawMgpObject(memory, impl->InsertVertex(), graph); }, graph->impl); + // TODO antepusic update text index + if (memgraph::flags::run_time::GetExperimentalTextSearchEnabled()) { + auto v_impl = vertex->getImpl(); + vertex->graph->getImpl()->TextIndexAddVertex(&v_impl); + } auto &ctx = graph->ctx; ctx->execution_stats[memgraph::query::ExecutionStats::Key::CREATED_NODES] += 1; diff --git a/src/query/procedure/mg_procedure_impl.hpp b/src/query/procedure/mg_procedure_impl.hpp index 17cac4eca..a91b4386c 100644 --- a/src/query/procedure/mg_procedure_impl.hpp +++ b/src/query/procedure/mg_procedure_impl.hpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -562,6 +562,13 @@ struct mgp_graph { memgraph::query::ExecutionContext *ctx; memgraph::storage::StorageMode storage_mode; + memgraph::query::DbAccessor *getImpl() const { + return std::visit( + memgraph::utils::Overloaded{[](memgraph::query::DbAccessor *impl) { return impl; }, + [](memgraph::query::SubgraphDbAccessor *impl) { return impl->GetAccessor(); }}, + this->impl); + } + static mgp_graph WritableGraph(memgraph::query::DbAccessor &acc, memgraph::storage::View view, memgraph::query::ExecutionContext &ctx) { return mgp_graph{&acc, view, &ctx, acc.GetStorageMode()}; diff --git a/src/storage/v2/storage.cpp b/src/storage/v2/storage.cpp index 0accfbf9f..29e37f5d8 100644 --- a/src/storage/v2/storage.cpp +++ b/src/storage/v2/storage.cpp @@ -149,10 +149,6 @@ Result> Storage::Accessor::DeleteVertex(VertexAcce return res.GetError(); } - if (flags::run_time::GetExperimentalTextSearchEnabled()) { - storage_->indices_.text_index_.RemoveNode(vertex->vertex_); - } - const auto &value = res.GetValue(); if (!value) { return std::optional{}; @@ -190,10 +186,6 @@ Result>>> Stor return res.GetError(); } - if (flags::run_time::GetExperimentalTextSearchEnabled()) { - storage_->indices_.text_index_.RemoveNode(vertex->vertex_); - } - auto &value = res.GetValue(); if (!value) { return std::optional{};