From 3b2f42e1bced72b6ae3641e436795ebfdd0f4fce Mon Sep 17 00:00:00 2001 From: Harpreet Sangar Date: Mon, 30 Jan 2023 10:31:29 +0530 Subject: [PATCH] Fix `Index::get_filter_matches`. --- src/index.cpp | 6 ++---- test/collection_filtering_test.cpp | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/index.cpp b/src/index.cpp index 9e41b70e..056fe4f8 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -2024,9 +2024,6 @@ void Index::get_filter_matches(filter_node_t* const root, std::vectorleft, vec); - get_filter_matches(root->right, vec); - if (root->isOperator && root->filter_operator == OR) { uint32_t* l_filter_ids = nullptr; uint32_t l_filter_ids_length = 0; @@ -2052,7 +2049,8 @@ void Index::get_filter_matches(filter_node_t* const root, std::vectormatch_index_ids.first, root); } else { - // malformed + get_filter_matches(root->left, vec); + get_filter_matches(root->right, vec); } } diff --git a/test/collection_filtering_test.cpp b/test/collection_filtering_test.cpp index 2039c5e7..39a4c76a 100644 --- a/test/collection_filtering_test.cpp +++ b/test/collection_filtering_test.cpp @@ -2590,17 +2590,17 @@ TEST_F(CollectionFilteringTest, ComplexFilterQuery) { ASSERT_STREQ(id.c_str(), result_id.c_str()); } -// results = coll->search("Jeremy", {"name"}, "years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))", -// {}, sort_fields_desc, {0}, 10, 1, FREQUENCY, {false}).get(); -// ASSERT_EQ(1, results["hits"].size()); -// -// ids = {"2"}; -// for (size_t i = 0; i < results["hits"].size(); i++) { -// nlohmann::json result = results["hits"].at(i); -// std::string result_id = result["document"]["id"]; -// std::string id = ids.at(i); -// ASSERT_STREQ(id.c_str(), result_id.c_str()); -// } + results = coll->search("Jeremy", {"name"}, "years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))", + {}, sort_fields_desc, {0}, 10, 1, FREQUENCY, {false}).get(); + ASSERT_EQ(1, results["hits"].size()); + + ids = {"2"}; + for (size_t i = 0; i < results["hits"].size(); i++) { + nlohmann::json result = results["hits"].at(i); + std::string result_id = result["document"]["id"]; + std::string id = ids.at(i); + ASSERT_STREQ(id.c_str(), result_id.c_str()); + } collectionManager.drop_collection("ComplexFilterQueryCollection"); } \ No newline at end of file