Skip to content

Commit 0a351b7

Browse files
authored
Add relevance score and limit to text search. Add aggregation queries to text edge index (memgraph#3264)
This PR adds a relevance score to the output of text search queries, introduces a limit option as an input parameter, and adds support for aggregation queries on the text edge index.
1 parent da2a17a commit 0a351b7

18 files changed

Lines changed: 446 additions & 195 deletions

File tree

include/_mgp.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ inline bool graph_has_text_index(mgp_graph *graph, const char *index_name) {
330330
}
331331

332332
inline mgp_map *graph_search_text_index(mgp_graph *graph, const char *index_name, const char *search_query,
333-
text_search_mode search_mode, mgp_memory *memory) {
334-
return MgInvoke<mgp_map *>(mgp_graph_search_text_index, graph, index_name, search_query, search_mode, memory);
333+
text_search_mode search_mode, std::size_t limit, mgp_memory *memory) {
334+
return MgInvoke<mgp_map *>(mgp_graph_search_text_index, graph, index_name, search_query, search_mode, limit, memory);
335335
}
336336

337337
inline mgp_map *graph_aggregate_over_text_index(mgp_graph *graph, const char *index_name, const char *search_query,
@@ -341,8 +341,15 @@ inline mgp_map *graph_aggregate_over_text_index(mgp_graph *graph, const char *in
341341
}
342342

343343
inline mgp_map *graph_search_text_edge_index(mgp_graph *graph, const char *index_name, const char *search_query,
344-
text_search_mode search_mode, mgp_memory *memory) {
345-
return MgInvoke<mgp_map *>(mgp_graph_search_text_edge_index, graph, index_name, search_query, search_mode, memory);
344+
text_search_mode search_mode, std::size_t limit, mgp_memory *memory) {
345+
return MgInvoke<mgp_map *>(mgp_graph_search_text_edge_index, graph, index_name, search_query, search_mode, limit,
346+
memory);
347+
}
348+
349+
inline mgp_map *graph_aggregate_over_text_edge_index(mgp_graph *graph, const char *index_name, const char *search_query,
350+
const char *aggregation_query, mgp_memory *memory) {
351+
return MgInvoke<mgp_map *>(mgp_graph_aggregate_over_text_edge_index, graph, index_name, search_query,
352+
aggregation_query, memory);
346353
}
347354

348355
inline mgp_vertices_iterator *graph_iter_vertices(mgp_graph *g, mgp_memory *memory) {

include/mg_procedure.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ MGP_ENUM_CLASS text_search_mode{
957957
/// Return mgp_error::MGP_ERROR_UNABLE_TO_ALLOCATE if there’s an allocation error while constructing the results map.
958958
/// Return mgp_error::MGP_ERROR_KEY_ALREADY_EXISTS if the same key is being created in the results map more than once.
959959
enum mgp_error mgp_graph_search_text_index(struct mgp_graph *graph, const char *index_name, const char *search_query,
960-
enum text_search_mode search_mode, struct mgp_memory *memory,
960+
enum text_search_mode search_mode, size_t limit, struct mgp_memory *memory,
961961
struct mgp_map **result);
962962

963963
/// Aggregate over the results of a search over the named text index. The result is a map with the "aggregation_results"
@@ -970,9 +970,13 @@ enum mgp_error mgp_graph_aggregate_over_text_index(struct mgp_graph *graph, cons
970970
const char *search_query, const char *aggregation_query,
971971
struct mgp_memory *memory, struct mgp_map **result);
972972

973+
enum mgp_error mgp_graph_aggregate_over_text_edge_index(struct mgp_graph *graph, const char *index_name,
974+
const char *search_query, const char *aggregation_query,
975+
struct mgp_memory *memory, struct mgp_map **result);
976+
973977
enum mgp_error mgp_graph_search_text_edge_index(struct mgp_graph *graph, const char *index_name,
974978
const char *search_query, enum text_search_mode search_mode,
975-
struct mgp_memory *memory, struct mgp_map **result);
979+
size_t limit, struct mgp_memory *memory, struct mgp_map **result);
976980

977981
enum mgp_error mgp_graph_search_vector_index(struct mgp_graph *graph, const char *index_name, struct mgp_list *query,
978982
int result_size, struct mgp_memory *memory, struct mgp_map **result);

include/mgp.hpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4767,9 +4767,9 @@ inline constexpr std::string_view kSearchResultsKey = "search_results";
47674767
inline constexpr std::string_view kAggregationResultsKey = "aggregation_results";
47684768

47694769
inline List SearchTextIndex(mgp_graph *memgraph_graph, std::string_view index_name, std::string_view search_query,
4770-
text_search_mode search_mode) {
4770+
text_search_mode search_mode, std::size_t limit) {
47714771
auto results_or_error = Map(mgp::MemHandlerCallback(graph_search_text_index, memgraph_graph, index_name.data(),
4772-
search_query.data(), search_mode),
4772+
search_query.data(), search_mode, limit),
47734773
StealType{});
47744774
if (results_or_error.KeyExists(kErrorMsgKey)) {
47754775
if (!results_or_error.At(kErrorMsgKey).IsString()) {
@@ -4790,9 +4790,9 @@ inline List SearchTextIndex(mgp_graph *memgraph_graph, std::string_view index_na
47904790
}
47914791

47924792
inline List SearchTextEdgeIndex(mgp_graph *memgraph_graph, std::string_view index_name, std::string_view search_query,
4793-
text_search_mode search_mode) {
4793+
text_search_mode search_mode, std::size_t limit) {
47944794
auto results_or_error = Map(mgp::MemHandlerCallback(graph_search_text_edge_index, memgraph_graph, index_name.data(),
4795-
search_query.data(), search_mode),
4795+
search_query.data(), search_mode, limit),
47964796
StealType{});
47974797
if (results_or_error.KeyExists(kErrorMsgKey)) {
47984798
if (!results_or_error.At(kErrorMsgKey).IsString()) {
@@ -4837,6 +4837,29 @@ inline std::string AggregateOverTextIndex(mgp_graph *memgraph_graph, std::string
48374837
return std::string(results_or_error.At(kAggregationResultsKey).ValueString());
48384838
}
48394839

4840+
inline std::string AggregateOverTextEdgeIndex(mgp_graph *memgraph_graph, std::string_view index_name,
4841+
std::string_view search_query, std::string_view aggregation_query) {
4842+
auto results_or_error = Map(mgp::MemHandlerCallback(graph_aggregate_over_text_edge_index, memgraph_graph,
4843+
index_name.data(), search_query.data(), aggregation_query.data()),
4844+
StealType{});
4845+
4846+
if (results_or_error.KeyExists(kErrorMsgKey)) {
4847+
if (!results_or_error.At(kErrorMsgKey).IsString()) {
4848+
throw TextSearchException{"The error message is not a string!"};
4849+
}
4850+
throw TextSearchException(results_or_error.At(kErrorMsgKey).ValueString().data());
4851+
}
4852+
4853+
if (!results_or_error.KeyExists(kAggregationResultsKey)) {
4854+
throw TextSearchException{"Incomplete text edge index aggregation results!"};
4855+
}
4856+
4857+
if (!results_or_error.At(kAggregationResultsKey).IsString()) {
4858+
throw TextSearchException{"Text edge index aggregation results have wrong type!"};
4859+
}
4860+
return std::string(results_or_error.At(kAggregationResultsKey).ValueString());
4861+
}
4862+
48404863
inline List SearchVectorIndex(mgp_graph *memgraph_graph, std::string_view index_name, List &query_vector,
48414864
size_t result_size) {
48424865
auto results_or_error = Map(mgp::MemHandlerCallback(graph_search_vector_index, memgraph_graph, index_name.data(),

init

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ else
5353
OS_SCRIPT=$DIR/environment/os/$DISTRO.sh
5454
fi
5555
echo "ALL BUILD PACKAGES: $($OS_SCRIPT list MEMGRAPH_BUILD_DEPS)"
56-
$OS_SCRIPT check MEMGRAPH_BUILD_DEPS
57-
echo "All packages are in-place..."
56+
if [[ "$check_system_packages" == "true" ]]; then
57+
$OS_SCRIPT check MEMGRAPH_BUILD_DEPS
58+
echo "All packages are in-place..."
59+
else
60+
echo "Skipping package check as requested..."
61+
fi
5862

5963
# create a default build directory
6064
mkdir -p ./build

libs/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ else
349349
fi
350350

351351
# mgcxx (text search)
352-
mgcxx_tag="v0.0.9"
352+
mgcxx_tag="v0.0.10"
353353
repo_clone_try_double "${primary_urls[mgcxx]}" "${secondary_urls[mgcxx]}" "mgcxx" "$mgcxx_tag" true
354354

355355
# strong_type v14

0 commit comments

Comments
 (0)