memgraph/query_modules/text_search.cpp

65 lines
2.4 KiB
C++
Raw Normal View History

2024-01-04 17:34:58 +08:00
// 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
// License, and you may not use this file except in compliance with the Business Source License.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
#include <mgp.hpp>
2024-01-05 20:32:45 +08:00
// #include "query/procedure/mg_procedure_impl.hpp"
#include "utils/memcxx.hpp"
2024-01-04 17:34:58 +08:00
namespace TextSearch {
constexpr std::string_view kProcedureSearch = "search";
constexpr std::string_view kParameterLabel = "label";
constexpr std::string_view kParameterSearchString = "search_string";
constexpr std::string_view kReturnNode = "node";
void Search(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory);
} // namespace TextSearch
void Search(mgp_list *args, mgp_graph *memgraph_graph, mgp_result *result, mgp_memory *memory) {
mgp::MemoryDispatcherGuard guard{memory};
const auto record_factory = mgp::RecordFactory(result);
auto arguments = mgp::List(args);
auto label = arguments[0].ValueString();
auto search_string = arguments[1].ValueString();
// TODO antepusic:
// 1. Match the label to the appropriate text index
2024-01-05 20:32:45 +08:00
// auto label_id = memgraph_graph->impl->NameToLabel(label);
2024-01-04 17:34:58 +08:00
// 2. Run text search of that index
// * Add metadata to the return fields before search
2024-01-05 20:32:45 +08:00
// text_index.search(label, search_string);
2024-01-04 17:34:58 +08:00
// 3. Get the graph elements from their IDs in the search results
2024-01-05 20:32:45 +08:00
2024-01-04 17:34:58 +08:00
// 4. Return records (one per element)
}
extern "C" int mgp_init_module(struct mgp_module *module, struct mgp_memory *memory) {
try {
mgp::MemoryDispatcherGuard guard{memory};
AddProcedure(TextSearch::Search, TextSearch::kProcedureSearch, mgp::ProcedureType::Read,
{
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) {
std::cerr << "Error while initializing query module: " << e.what() << std::endl;
return 1;
}
return 0;
}
extern "C" int mgp_shutdown_module() { return 0; }