Add work on the search query procedure
This commit is contained in:
parent
584d86e774
commit
2ec08f7da5
@ -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
|
||||
@ -326,6 +326,10 @@ inline mgp_vertex *graph_get_vertex_by_id(mgp_graph *g, mgp_vertex_id id, mgp_me
|
||||
return MgInvoke<mgp_vertex *>(mgp_graph_get_vertex_by_id, g, id, memory);
|
||||
}
|
||||
|
||||
inline bool graph_has_text_index(mgp_graph *graph, const char *label) {
|
||||
return MgInvoke<int>(mgp_graph_has_text_index, graph, label);
|
||||
}
|
||||
|
||||
inline mgp_vertices_iterator *graph_iter_vertices(mgp_graph *g, mgp_memory *memory) {
|
||||
return MgInvoke<mgp_vertices_iterator *>(mgp_graph_iter_vertices, g, memory);
|
||||
}
|
||||
|
@ -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
|
||||
@ -891,6 +891,8 @@ enum mgp_error mgp_edge_iter_properties(struct mgp_edge *e, struct mgp_memory *m
|
||||
enum mgp_error mgp_graph_get_vertex_by_id(struct mgp_graph *g, struct mgp_vertex_id id, struct mgp_memory *memory,
|
||||
struct mgp_vertex **result);
|
||||
|
||||
enum mgp_error mgp_graph_has_text_index(mgp_graph *graph, const char *label);
|
||||
|
||||
/// Creates label index for given label.
|
||||
/// mgp_error::MGP_ERROR_NO_ERROR is always returned.
|
||||
/// if label index already exists, result will be 0, otherwise 1.
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include <mgp.hpp>
|
||||
// #include "query/procedure/mg_procedure_impl.hpp"
|
||||
// #include "storage/v2/indices/mgcxx_mock.hpp"
|
||||
#include "storage/v2/mgcxx_mock.hpp"
|
||||
|
||||
namespace TextSearch {
|
||||
@ -31,7 +32,11 @@ void Search(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_m
|
||||
|
||||
// TODO antepusic:
|
||||
// 1. Match the label to the appropriate text index
|
||||
// auto label_id = memgraph_graph->impl->NameToLabel(label);
|
||||
// auto label_id = memgraph_graph->impl->NameToLabel(label); <- needs API method
|
||||
|
||||
if (!mgp::graph_has_text_index(memgraph_graph, label.data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Run text search of that index
|
||||
// * Add metadata to the return fields before search
|
||||
@ -49,8 +54,8 @@ extern "C" int mgp_init_module(struct mgp_module *module, struct mgp_memory *mem
|
||||
|
||||
AddProcedure(TextSearch::Search, TextSearch::kProcedureSearch, mgp::ProcedureType::Read,
|
||||
{
|
||||
mgp::Parameter(TextSearch::kParameterLabel, {mgp::Type::String}),
|
||||
mgp::Parameter(TextSearch::kParameterSearchString, {mgp::Type::String}),
|
||||
mgp::Parameter(TextSearch::kParameterLabel, mgp::Type::String),
|
||||
mgp::Parameter(TextSearch::kParameterSearchString, mgp::Type::String),
|
||||
},
|
||||
{mgp::Return(TextSearch::kReturnNode, mgp::Type::Node)}, module, memory);
|
||||
} catch (const std::exception &e) {
|
||||
|
@ -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
|
||||
@ -3322,6 +3322,18 @@ mgp_error mgp_graph_delete_edge(struct mgp_graph *graph, mgp_edge *edge) {
|
||||
});
|
||||
}
|
||||
|
||||
mgp_error mgp_graph_has_text_index(mgp_graph *graph, const char *label, int *result) {
|
||||
return WrapExceptions([graph, label, result]() {
|
||||
std::visit(
|
||||
memgraph::utils::Overloaded{
|
||||
[&](memgraph::query::DbAccessor *impl) { *result = impl->TextIndexExists(impl->NameToLabel(label)); },
|
||||
[&](memgraph::query::SubgraphDbAccessor *impl) {
|
||||
*result = impl->GetAccessor()->TextIndexExists(impl->GetAccessor()->NameToLabel(label));
|
||||
}},
|
||||
graph->impl);
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef MG_ENTERPRISE
|
||||
namespace {
|
||||
void NextPermitted(mgp_vertices_iterator &it) {
|
||||
|
Loading…
Reference in New Issue
Block a user