Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Fix `Index::get_filter_matches`.

Harpreet Sangar3b2f42e1bced
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::vector<std::pair<
return;
}
- get_filter_matches(root->left, 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::vector<std::pair<
do_filtering(root);
vec.emplace_back(root->match_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