diff --git a/src/storage/v2/indices/text_index.hpp b/src/storage/v2/indices/text_index.hpp index d3935edde..3c98bec22 100644 --- a/src/storage/v2/indices/text_index.hpp +++ b/src/storage/v2/indices/text_index.hpp @@ -28,6 +28,16 @@ class TextIndex { void UpdateOnRemoveLabel(LabelId removed_label, Vertex *vertex_after_update, const Transaction &tx) {} + std::vector GetApplicableTextIndices(Vertex *vertex, Storage *storage) { + std::vector applicable_text_indices; + for (const auto &label : vertex->labels) { + if (label_to_index_.contains(label)) { + applicable_text_indices.push_back(&index_.at(label_to_index_.at(label))); + } + } + return applicable_text_indices; + } + /// @throw std::bad_alloc bool CreateIndex(std::string index_name, LabelId label, const std::optional ¶llel_exec_info) { @@ -64,6 +74,7 @@ class TextIndex { uint64_t ApproximateVertexCount(std::string index_name) { return 10; } std::map index_; + std::map label_to_index_; }; } // namespace memgraph::storage diff --git a/src/storage/v2/vertex_accessor.cpp b/src/storage/v2/vertex_accessor.cpp index 02eea0ed8..a4dd501b9 100644 --- a/src/storage/v2/vertex_accessor.cpp +++ b/src/storage/v2/vertex_accessor.cpp @@ -275,25 +275,15 @@ Result VertexAccessor::SetProperty(PropertyId property, const Pro [transaction = transaction_, storage = storage_, vertex = vertex_, &value, &property, ¤t_value]() { CreateAndLinkDelta(transaction, vertex, Delta::SetPropertyTag(), property, current_value); if (flags::run_time::GetTextSearchEnabled()) { - // if (!storage->indices_.text_index_->IndexExists(storage->NameToLabel(name))) continue; - // TODO antepusic: check which text indices apply - // for (const auto index : GetApplicableTextIndices(vertex)) { - // - // } - for (auto label : vertex->labels) { - auto &context = storage->indices_.text_index_->index_.at("myIndex"); - - // Calling the text search tool is done here and not inside a PropertyStore method - // make SearchInput - + for (const auto *index_context : storage->indices_.text_index_->GetApplicableTextIndices(vertex, storage)) { auto search_input = mgcxx_mock::text_search::SearchInput{}; - auto search_result = mgcxx_mock::text_search::Mock::search(context, search_input); - mgcxx_mock::text_search::Mock::delete_document(context, search_input, true); + auto search_result = mgcxx_mock::text_search::Mock::search(*index_context, search_input); + mgcxx_mock::text_search::Mock::delete_document(*index_context, search_input, true); // parse result to JSON, set property in JSON and convert to string auto new_properties = search_result.docs[0].data; auto new_properties_document = mgcxx_mock::text_search::DocumentInput{.data = new_properties}; - mgcxx_mock::text_search::Mock::add(context, new_properties_document, true); + mgcxx_mock::text_search::Mock::add(*index_context, new_properties_document, true); } } vertex->properties.SetProperty(property, value);