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 `parse_nested_include`.

Harpreet Sangara11d0f7a652f
diff --git a/src/collection_manager.cpp b/src/collection_manager.cpp
index 8151c095..1758a69e 100644
--- a/src/collection_manager.cpp
+++ b/src/collection_manager.cpp
@@ -1049,6 +1049,7 @@ Option<bool> parse_nested_include(const std::string& include_field_exp,
}
StringUtils::trim(ref_fields);
+ index = closing_parenthesis_pos;
auto as_pos = include_field_exp.find(" as ", index);
comma_pos = include_field_exp.find(',', index);
if (as_pos != std::string::npos && as_pos < comma_pos) {
diff --git a/test/collection_manager_test.cpp b/test/collection_manager_test.cpp
index a4178dc2..4a7da68a 100644
--- a/test/collection_manager_test.cpp
+++ b/test/collection_manager_test.cpp
@@ -1515,6 +1515,30 @@ TEST_F(CollectionManagerTest, InitializeRefIncludeFields) {
ASSERT_TRUE(ref_include_fields_vec[0].nested_join_includes.empty());
ref_include_fields_vec.clear();
+ filter_query = "$product_variants( $inventory($retailers(location:(33.865,-118.375,100 km))))";
+ include_fields_vec = {"$product_variants(id,$inventory(qty,sku,$retailers(id,title)))"};
+ initialize_op = CollectionManager::_initialize_ref_include_fields_vec(filter_query, include_fields_vec,
+ ref_include_fields_vec);
+ ASSERT_TRUE(initialize_op.ok());
+ ASSERT_EQ(1, ref_include_fields_vec.size());
+ ASSERT_EQ("product_variants", ref_include_fields_vec[0].collection_name);
+ ASSERT_EQ("id,", ref_include_fields_vec[0].fields);
+ ASSERT_TRUE(ref_include_fields_vec[0].alias.empty());
+ ASSERT_EQ(ref_include::nest, ref_include_fields_vec[0].strategy);
+
+ auto nested_join_includes = ref_include_fields_vec[0].nested_join_includes;
+ ASSERT_EQ("inventory", nested_join_includes[0].collection_name);
+ ASSERT_EQ("qty,sku,", nested_join_includes[0].fields);
+ ASSERT_TRUE(nested_join_includes[0].alias.empty());
+ ASSERT_EQ(ref_include::nest, nested_join_includes[0].strategy);
+
+ nested_join_includes = ref_include_fields_vec[0].nested_join_includes[0].nested_join_includes;
+ ASSERT_EQ("retailers", nested_join_includes[0].collection_name);
+ ASSERT_EQ("id,title", nested_join_includes[0].fields);
+ ASSERT_TRUE(nested_join_includes[0].alias.empty());
+ ASSERT_EQ(ref_include::nest, ref_include_fields_vec[0].strategy);
+ ref_include_fields_vec.clear();
+
filter_query = "$product_variants( $inventory($retailers(location:(33.865,-118.375,100 km))))";
include_fields_vec = {"$product_variants(title, $inventory(qty:merge) as inventory: nest) as variants"};
initialize_op = CollectionManager::_initialize_ref_include_fields_vec(filter_query, include_fields_vec,
@@ -1526,7 +1550,7 @@ TEST_F(CollectionManagerTest, InitializeRefIncludeFields) {
ASSERT_EQ("variants", ref_include_fields_vec[0].alias);
ASSERT_EQ(ref_include::nest, ref_include_fields_vec[0].strategy);
- auto nested_join_includes = ref_include_fields_vec[0].nested_join_includes;
+ nested_join_includes = ref_include_fields_vec[0].nested_join_includes;
ASSERT_EQ("inventory", nested_join_includes[0].collection_name);
ASSERT_EQ("qty", nested_join_includes[0].fields);
ASSERT_EQ("inventory.", nested_join_includes[0].alias);