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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Refactor tests.
Harpreet Sangardb555d36ad43
diff --git a/include/index.h b/include/index.hindex f7b5f3fe..ff8431c8 100644--- a/include/index.h+++ b/include/index.h@@ -486,14 +486,6 @@ private:const int64_t& range_end_value,uint32_t& filter_ids_length) const;- Option<bool> approximate_filter_ids(const filter& a_filter,- uint32_t& filter_ids_length,- const std::string& collection_name) const;-- Option<bool> rearranging_recursive_filter(filter_node_t* const filter_tree_root,- filter_result_t& result,- const std::string& collection_name = "") const;-Option<bool> recursive_filter(filter_node_t* const root,filter_result_t& result,const std::string& collection_name = "") const;@@ -502,10 +494,6 @@ private:filter_result_t& result,const std::string& collection_name = "") const;- Option<bool> rearrange_filter_tree(filter_node_t* const root,- uint32_t& filter_ids_length,- const std::string& collection_name = "") const;-void insert_doc(const int64_t score, art_tree *t, uint32_t seq_id,const std::unordered_map<std::string, std::vector<uint32_t>> &token_to_offsets) const;@@ -701,6 +689,18 @@ public:filter_result_t& filter_result,const std::string& collection_name = "") const;+ Option<bool> _rearranging_recursive_filter(filter_node_t* const filter_tree_root,+ filter_result_t& result,+ const std::string& collection_name = "") const;++ Option<bool> _rearrange_filter_tree(filter_node_t* const root,+ uint32_t& filter_ids_length,+ const std::string& collection_name = "") const;++ Option<bool> _approximate_filter_ids(const filter& a_filter,+ uint32_t& filter_ids_length,+ const std::string& collection_name = "") const;+Option<bool> do_reference_filtering_with_lock(filter_node_t* const filter_tree_root,filter_result_t& filter_result,const std::string& collection_name,diff --git a/src/index.cpp b/src/index.cppindex b704356d..124cf567 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -1952,7 +1952,7 @@ void Index::aproximate_numerical_match(num_tree_t* const num_tree,num_tree->approx_search_count(comparator, value, filter_ids_length);}-Option<bool> Index::approximate_filter_ids(const filter& a_filter,+Option<bool> Index::_approximate_filter_ids(const filter& a_filter,uint32_t& filter_ids_length,const std::string& collection_name) const {if (!a_filter.referenced_collection_name.empty()) {@@ -2054,7 +2054,7 @@ Option<bool> Index::approximate_filter_ids(const filter& a_filter,return Option(true);}-Option<bool> Index::rearrange_filter_tree(filter_node_t* const root,+Option<bool> Index::_rearrange_filter_tree(filter_node_t* const root,uint32_t& filter_ids_length,const std::string& collection_name) const {if (root == nullptr) {@@ -2064,7 +2064,7 @@ Option<bool> Index::rearrange_filter_tree(filter_node_t* const root,if (root->isOperator) {uint32_t l_filter_ids_length = 0;if (root->left != nullptr) {- auto rearrange_op = rearrange_filter_tree(root->left, l_filter_ids_length, collection_name);+ auto rearrange_op = _rearrange_filter_tree(root->left, l_filter_ids_length, collection_name);if (!rearrange_op.ok()) {return rearrange_op;}@@ -2072,7 +2072,7 @@ Option<bool> Index::rearrange_filter_tree(filter_node_t* const root,uint32_t r_filter_ids_length = 0;if (root->right != nullptr) {- auto rearrange_op = rearrange_filter_tree(root->right, r_filter_ids_length, collection_name);+ auto rearrange_op = _rearrange_filter_tree(root->right, r_filter_ids_length, collection_name);if (!rearrange_op.ok()) {return rearrange_op;}@@ -2091,15 +2091,15 @@ Option<bool> Index::rearrange_filter_tree(filter_node_t* const root,return Option(true);}- approximate_filter_ids(root->filter_exp, filter_ids_length, collection_name);+ _approximate_filter_ids(root->filter_exp, filter_ids_length, collection_name);return Option(true);}-Option<bool> Index::rearranging_recursive_filter(filter_node_t* const filter_tree_root,+Option<bool> Index::_rearranging_recursive_filter(filter_node_t* const filter_tree_root,filter_result_t& result,const std::string& collection_name) const {uint32_t filter_ids_length = 0;- auto rearrange_op = rearrange_filter_tree(filter_tree_root, filter_ids_length, collection_name);+ auto rearrange_op = _rearrange_filter_tree(filter_tree_root, filter_ids_length, collection_name);if (!rearrange_op.ok()) {return rearrange_op;}@@ -2189,7 +2189,7 @@ Option<bool> Index::adaptive_filter(filter_node_t* const filter_tree_root,metrics->and_operator_count > 0 &&// If there are more || in the filter tree than &&, we'll not gain much by rearranging the filter tree.((float) metrics->or_operator_count / (float) metrics->and_operator_count < 0.5)) {- return rearranging_recursive_filter(filter_tree_root, result, collection_name);+ return _rearranging_recursive_filter(filter_tree_root, result, collection_name);} else {return recursive_filter(filter_tree_root, result, collection_name);}@@ -2252,7 +2252,7 @@ Option<bool> Index::get_approximate_reference_filter_ids_with_lock(filter_node_tuint32_t& filter_ids_length) const {std::shared_lock lock(mutex);- return rearrange_filter_tree(filter_tree_root, filter_ids_length);+ return _rearrange_filter_tree(filter_tree_root, filter_ids_length);}Option<bool> Index::run_search(search_args* search_params, const std::string& collection_name) {diff --git a/test/collection_specific_more_test.cpp b/test/collection_specific_more_test.cppindex 8afdaf84..b34b9973 100644--- a/test/collection_specific_more_test.cpp+++ b/test/collection_specific_more_test.cpp@@ -2077,8 +2077,7 @@ TEST_F(CollectionSpecificMoreTest, RearrangingFilterTree) {ASSERT_TRUE(root->right == nullptr);filter_result_t result;- // Internally calls rearranging_recursive_filter- coll->_get_index()->do_filtering_with_lock(filter_tree_root, result);+ coll->_get_index()->_rearranging_recursive_filter(filter_tree_root, result);// &&// / \@@ -2150,6 +2149,8 @@ TEST_F(CollectionSpecificMoreTest, RearrangingFilterTree) {ASSERT_EQ(root->filter_exp.field_name, "years");ASSERT_TRUE(root->left == nullptr);ASSERT_TRUE(root->right == nullptr);++ collectionManager.drop_collection("Collection");}TEST_F(CollectionSpecificMoreTest, ApproxFilterMatchCount) {@@ -2160,7 +2161,8 @@ TEST_F(CollectionSpecificMoreTest, ApproxFilterMatchCount) {{"name": "name", "type": "string"},{"name": "age", "type": "int32"},{"name": "years", "type": "int32[]"},- {"name": "rating", "type": "float"}+ {"name": "rating", "type": "float"},+ {"name": "location", "type": "geopoint", "optional": true}]})"_json;@@ -2174,8 +2176,32 @@ TEST_F(CollectionSpecificMoreTest, ApproxFilterMatchCount) {}infile.close();+ const std::string doc_id_prefix = std::to_string(coll->get_collection_id()) + "_" + Collection::DOC_ID_PREFIX + "_";+ filter_node_t* filter_tree_root = nullptr;+ Option<bool> filter_op = filter::parse_filter_query("name: Jeremy", coll->get_schema(), store, doc_id_prefix,+ filter_tree_root);+ ASSERT_TRUE(filter_op.ok());+uint32_t approx_count;- coll->get_approximate_reference_filter_ids("years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))",- approx_count);+ coll->_get_index()->_approximate_filter_ids(filter_tree_root->filter_exp, approx_count);+ ASSERT_EQ(approx_count, 5);++ delete filter_tree_root;+ filter_op = filter::parse_filter_query("location:(48.8662, 2.3255, 48.8581, 2.3209, 48.8561, 2.3448, 48.8641, 2.3469)",+ coll->get_schema(), store, doc_id_prefix, filter_tree_root);+ ASSERT_TRUE(filter_op.ok());++ coll->_get_index()->_approximate_filter_ids(filter_tree_root->filter_exp, approx_count);+ ASSERT_EQ(approx_count, 100);++ delete filter_tree_root;+ filter_op = filter::parse_filter_query("years:>2000 && ((age:<30 && rating:>5) || (age:>50 && rating:<5))",+ coll->get_schema(), store, doc_id_prefix, filter_tree_root);+ ASSERT_TRUE(filter_op.ok());++ coll->_get_index()->_rearrange_filter_tree(filter_tree_root, approx_count);ASSERT_EQ(approx_count, 3);++ delete filter_tree_root;+ collectionManager.drop_collection("Collection");}\ No newline at end of file