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
Return error when applying embedded filter_by fails. (#1940)
Harpreet Sangard1e2723b7b97
diff --git a/src/collection_manager.cpp b/src/collection_manager.cppindex 20fd6a5d..4f3c4943 100644--- a/src/collection_manager.cpp+++ b/src/collection_manager.cpp@@ -1273,7 +1273,9 @@ Option<bool> CollectionManager::do_search(std::map<std::string, std::string>& re}// overwrite = true as embedded params have higher priority- AuthManager::add_item_to_params(req_params, item, true);+ if (!AuthManager::add_item_to_params(req_params, item, true)) {+ return Option<bool>(400, "Error while applying embedded parameters.");+ }}const auto preset_it = req_params.find("preset");diff --git a/test/collection_join_test.cpp b/test/collection_join_test.cppindex 6fddda51..3c8d5660 100644--- a/test/collection_join_test.cpp+++ b/test/collection_join_test.cpp@@ -7345,14 +7345,35 @@ TEST_F(CollectionJoinTest, EmbeddedParamsJoin) {ASSERT_EQ("$Customers((customer_id:customer_a) && product_price:<100)", query_filter);}+ // Malformed inputs{embedded_filter = " (( $Customers(customer_id:customer_a) )) ";query_filter = "$Customers(product_price:<100)";ASSERT_FALSE(Join::merge_join_conditions(embedded_filter, query_filter));+ embedded_filter = "$Customers(customer_id:customer_a)&&";+ query_filter = "$Customers(product_price:<100)";+ ASSERT_FALSE(Join::merge_join_conditions(embedded_filter, query_filter));++ embedded_filter = "$Customers(customer_id)&&";+ query_filter = "$Customers(product_price:<100)";+ ASSERT_FALSE(Join::merge_join_conditions(embedded_filter, query_filter));++ embedded_filter = "$Customers(custo";+ query_filter = "$Customers(product_price:<100)";+ ASSERT_FALSE(Join::merge_join_conditions(embedded_filter, query_filter));+embedded_filter = "field:value && $Customers(customer_id:customer_a) || foo:bar";query_filter = "$Customers(product_price:<100)";ASSERT_FALSE(Join::merge_join_conditions(embedded_filter, query_filter));++ embedded_filter = "field:value && $Customers(customer_id:customer_a) || $Customers(foo:bar)";+ query_filter = "$Customers(product_price:<100)";+ ASSERT_FALSE(Join::merge_join_conditions(embedded_filter, query_filter));++ embedded_filter = "field:value && $Customers(customer_id:customer_a) || foo:bar";+ query_filter = "$Customers(product_price:<100) || $Customers(foo:bar)";+ ASSERT_FALSE(Join::merge_join_conditions(embedded_filter, query_filter));}auto schema_json =@@ -7467,6 +7488,33 @@ TEST_F(CollectionJoinTest, EmbeddedParamsJoin) {ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers"].count("id"));ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers"].count("product_id"));ASSERT_EQ(73.5, res_obj["hits"][0]["document"]["Customers"]["product_price"]);++ req_params = {+ {"collection", "Products"},+ {"q", "*"},+ {"filter_by", "$Customers(product_price:<100)"},+ };+ embedded_params = R"({+ "filter_by": "$Customers(customer_id:customer_a) || $Customers(customer_id:customer_a) "+ })"_json;++ search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);+ ASSERT_FALSE(search_op.ok());+ ASSERT_EQ("Error while applying embedded parameters.", search_op.error());++ req_params = {+ {"collection", "Products"},+ {"q", "*"},+ {"filter_by", "$Customers(customer_id:customer_a) && $Customers(product_price:<100)"},+ };+ embedded_params.clear();++ search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);+ ASSERT_FALSE(search_op.ok());+ ASSERT_EQ("More than one joins found for collection `Customers` in the `filter_by`. Instead of providing separate "+ "join conditions like `$customer_product_prices(customer_id:=customer_a) && "+ "$customer_product_prices(custom_price:<100)`, the join condition should be provided as a single filter "+ "expression like `$customer_product_prices(customer_id:=customer_a && custom_price:<100)`", search_op.error());}TEST_F(CollectionJoinTest, QueryByReference) {