From 753aebb895a1e5a885079e63de719e13abf88b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Pu=C5=A1i=C4=87?= <ante.pusic@memgraph.io> Date: Tue, 9 Jan 2024 22:20:35 +0100 Subject: [PATCH] Connect text search to its query module --- include/_mgp.hpp | 4 ++-- include/mg_procedure.h | 3 ++- query_modules/text_search.cpp | 4 ++-- src/query/db_accessor.hpp | 4 ++++ src/query/procedure/mg_procedure_impl.cpp | 3 ++- src/storage/v2/indices/text_index.hpp | 3 ++- src/storage/v2/storage.hpp | 9 ++++++--- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/_mgp.hpp b/include/_mgp.hpp index 7b7311600..61c630751 100644 --- a/include/_mgp.hpp +++ b/include/_mgp.hpp @@ -331,8 +331,8 @@ inline bool graph_has_text_index(mgp_graph *graph, const char *index_name) { } // TODO antepusic change result type -inline bool graph_search_text_index(mgp_graph *graph, const char *index_name) { - return MgInvoke<int>(mgp_graph_has_text_index, graph, index_name); +inline bool graph_search_text_index(mgp_graph *graph, const char *index_name, const char *search_string) { + return MgInvoke<int>(mgp_graph_has_text_index, graph, index_name, search_string); } inline mgp_vertices_iterator *graph_iter_vertices(mgp_graph *g, mgp_memory *memory) { diff --git a/include/mg_procedure.h b/include/mg_procedure.h index 61d8854df..723d55ffc 100644 --- a/include/mg_procedure.h +++ b/include/mg_procedure.h @@ -894,7 +894,8 @@ enum mgp_error mgp_graph_get_vertex_by_id(struct mgp_graph *g, struct mgp_vertex enum mgp_error mgp_graph_has_text_index(mgp_graph *graph, const char *label, int *result); // TODO antepusic change result type -enum mgp_error mgp_graph_search_text_index(mgp_graph *graph, const char *index_name, int *result); +enum mgp_error mgp_graph_search_text_index(mgp_graph *graph, const char *index_name, const char *search_string, + int *result); /// Creates label index for given label. /// mgp_error::MGP_ERROR_NO_ERROR is always returned. diff --git a/query_modules/text_search.cpp b/query_modules/text_search.cpp index acd6c1649..e29bb5f4d 100644 --- a/query_modules/text_search.cpp +++ b/query_modules/text_search.cpp @@ -24,7 +24,7 @@ void Search(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_m } // namespace TextSearch void Search(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory) { - // CALL text_search.search("Label", "nekiQuery", searchFields, returnFields) RETURN node, score + // CALL text_search.search("Label", "someQuery", searchFields, returnFields) RETURN node, score mgp::MemoryDispatcherGuard guard{memory}; const auto record_factory = mgp::RecordFactory(result); @@ -38,7 +38,7 @@ void Search(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_m } // 2. Run text search of that index - mgp::graph_search_text_index(memgraph_graph, label.data()); + mgp::graph_search_text_index(memgraph_graph, label.data(), search_string); // text_index.search(label, search_string); diff --git a/src/query/db_accessor.hpp b/src/query/db_accessor.hpp index 1bce52d70..c9416138f 100644 --- a/src/query/db_accessor.hpp +++ b/src/query/db_accessor.hpp @@ -555,6 +555,10 @@ class DbAccessor final { bool TextIndexExists(std::string index_name) const { return accessor_->TextIndexExists(index_name); } + mgcxx_mock::text_search::SearchOutput SearchTextIndex(std::string index_name, std::string search_string) const { + return accessor_->SearchTextIndex(index_name, search_string); + } + std::optional<storage::LabelIndexStats> GetIndexStats(const storage::LabelId &label) const { return accessor_->GetIndexStats(label); } diff --git a/src/query/procedure/mg_procedure_impl.cpp b/src/query/procedure/mg_procedure_impl.cpp index 72d856bb7..075329578 100644 --- a/src/query/procedure/mg_procedure_impl.cpp +++ b/src/query/procedure/mg_procedure_impl.cpp @@ -3333,7 +3333,8 @@ mgp_error mgp_graph_has_text_index(mgp_graph *graph, const char *index_name, int }); } -mgp_error mgp_graph_search_text_index(mgp_graph *graph, const char *index_name, int *result) { +mgp_error mgp_graph_search_text_index(mgp_graph *graph, const char *index_name, const char *search_string, + int *result) { return WrapExceptions([graph, index_name, result]() { *result = 1; }); } diff --git a/src/storage/v2/indices/text_index.hpp b/src/storage/v2/indices/text_index.hpp index 3c98bec22..801b67290 100644 --- a/src/storage/v2/indices/text_index.hpp +++ b/src/storage/v2/indices/text_index.hpp @@ -57,8 +57,9 @@ class TextIndex { bool IndexExists(std::string index_name) { return index_.contains(index_name); } - mgcxx_mock::text_search::SearchOutput Search(std::string index_name, mgcxx_mock::text_search::SearchInput input) { + mgcxx_mock::text_search::SearchOutput Search(std::string index_name, std::string search_string) { // TODO antepusic: Add metadata to the return fields before search + auto input = mgcxx_mock::text_search::SearchInput{}; return mgcxx_mock::text_search::Mock::search(index_.at(index_name), input); } diff --git a/src/storage/v2/storage.hpp b/src/storage/v2/storage.hpp index 49ff86a57..5cd8dd2ea 100644 --- a/src/storage/v2/storage.hpp +++ b/src/storage/v2/storage.hpp @@ -216,6 +216,10 @@ class Storage { return storage_->indices_.text_index_->IndexExists(index_name); } + mgcxx_mock::text_search::SearchOutput SearchTextIndex(std::string index_name, std::string search_string) const { + return storage_->indices_.text_index_->Search(index_name, search_string); + } + virtual IndicesInfo ListAllIndices() const = 0; virtual ConstraintsInfo ListAllConstraints() const = 0; @@ -252,9 +256,8 @@ class Storage { std::vector<EdgeTypeId> ListAllPossiblyPresentEdgeTypes() const; - mgcxx_mock::text_search::SearchOutput TextSearch(std::string index_name, - mgcxx_mock::text_search::SearchInput &search_input) const { - return storage_->indices_.text_index_->Search(index_name, search_input); + mgcxx_mock::text_search::SearchOutput TextSearch(std::string index_name, std::string &search_string) const { + return storage_->indices_.text_index_->Search(index_name, search_string); } virtual utils::BasicResult<StorageIndexDefinitionError, void> CreateIndex(LabelId label) = 0;