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 `CollectionJoinTest, FilterByReferenceAlias`. (#1589)

Harpreet Sangarbe52fd0927ad
diff --git a/src/collection.cpp b/src/collection.cpp
index 836295ad..7ff1e91c 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -1122,6 +1122,9 @@ Option<bool> Collection::validate_and_standardize_sort_fields(const std::vector<
if (ref_collection == nullptr) {
return Option<bool>(400, "Referenced collection `" + ref_collection_name + "` in `sort_by` not found.");
}
+ // `CollectionManager::get_collection` accounts for collection alias being used and provides pointer to the
+ // original collection.
+ ref_collection_name = ref_collection->name;
auto sort_by_str = _sort_field.name.substr(parenthesis_index + 1,
_sort_field.name.size() - parenthesis_index - 2);
@@ -5164,13 +5167,16 @@ Option<bool> Collection::include_references(nlohmann::json& doc, const uint32_t&
const std::map<std::string, reference_filter_result_t>& reference_filter_results,
const std::vector<ref_include_exclude_fields>& ref_include_exclude_fields_vec) {
for (auto const& ref_include_exclude: ref_include_exclude_fields_vec) {
- auto const& ref_collection_name = ref_include_exclude.collection_name;
+ auto ref_collection_name = ref_include_exclude.collection_name;
auto& cm = CollectionManager::get_instance();
auto ref_collection = cm.get_collection(ref_collection_name);
if (ref_collection == nullptr) {
return Option<bool>(400, "Referenced collection `" + ref_collection_name + "` in `include_fields` not found.");
}
+ // `CollectionManager::get_collection` accounts for collection alias being used and provides pointer to the
+ // original collection.
+ ref_collection_name = ref_collection->name;
auto const joined_on_ref_collection = reference_filter_results.count(ref_collection_name) > 0,
has_filter_reference = (joined_on_ref_collection &&
@@ -5957,11 +5963,13 @@ Index* Collection::init_index() {
auto ref_coll_name = field.reference.substr(0, dot_index);
auto ref_field_name = field.reference.substr(dot_index + 1);
- reference_fields.emplace(field.name, reference_pair(ref_coll_name, ref_field_name));
-
auto& collectionManager = CollectionManager::get_instance();
auto ref_coll = collectionManager.get_collection(ref_coll_name);
if (ref_coll != nullptr) {
+ // `CollectionManager::get_collection` accounts for collection alias being used and provides pointer to
+ // the original collection.
+ ref_coll_name = ref_coll->name;
+
// Passing reference helper field helps perform operation on doc_id instead of field value.
ref_coll->add_referenced_in(name, field.name + fields::REFERENCE_HELPER_FIELD_SUFFIX);
} else {
@@ -5969,6 +5977,8 @@ Index* Collection::init_index() {
collectionManager.add_referenced_in_backlog(ref_coll_name,
reference_pair{name, field.name + fields::REFERENCE_HELPER_FIELD_SUFFIX});
}
+
+ reference_fields.emplace(field.name, reference_pair(ref_coll_name, ref_field_name));
}
}
diff --git a/src/collection_manager.cpp b/src/collection_manager.cpp
index bf22278e..b4b29e5f 100644
--- a/src/collection_manager.cpp
+++ b/src/collection_manager.cpp
@@ -244,8 +244,13 @@ void CollectionManager::_populate_referenced_ins(const std::string& collection_m
auto field_name = std::string(field["name"]) + fields::REFERENCE_HELPER_FIELD_SUFFIX;
std::vector<std::string> split_result;
StringUtils::split(field["reference"], split_result, ".");
- auto const& ref_coll_name = split_result.front();
+ auto ref_coll_name = split_result.front();
+ // Resolves alias if used in schema.
+ auto actual_ref_coll_it = CollectionManager::get_instance().collection_symlinks.find(ref_coll_name);
+ if (actual_ref_coll_it != CollectionManager::get_instance().collection_symlinks.end()) {
+ ref_coll_name = actual_ref_coll_it->second;
+ }
if (referenced_ins.count(ref_coll_name) == 0) {
referenced_ins.emplace(ref_coll_name, spp::sparse_hash_map<std::string, std::string>());
}
@@ -277,6 +282,22 @@ Option<bool> CollectionManager::load(const size_t collection_batch_size, const s
next_collection_id = 0;
}
+ // load aliases
+
+ std::string symlink_prefix_key = std::string(SYMLINK_PREFIX) + "_";
+ std::string upper_bound_key = std::string(SYMLINK_PREFIX) + "`"; // cannot inline this
+ rocksdb::Slice upper_bound(upper_bound_key);
+
+ rocksdb::Iterator* iter = store->scan(symlink_prefix_key, &upper_bound);
+ while(iter->Valid() && iter->key().starts_with(symlink_prefix_key)) {
+ std::vector<std::string> parts;
+ StringUtils::split(iter->key().ToString(), parts, symlink_prefix_key);
+ LOG(INFO) << "Loading symlink " << parts[0] << " to " << iter->value().ToString();
+ collection_symlinks[parts[0]] = iter->value().ToString();
+ iter->Next();
+ }
+ delete iter;
+
LOG(INFO) << "Loading upto " << collection_batch_size << " collections in parallel, "
<< document_batch_size << " documents at a time.";
@@ -349,21 +370,6 @@ Option<bool> CollectionManager::load(const size_t collection_batch_size, const s
return num_processed == num_collections;
});
- // load aliases
-
- std::string symlink_prefix_key = std::string(SYMLINK_PREFIX) + "_";
- std::string upper_bound_key = std::string(SYMLINK_PREFIX) + "`"; // cannot inline this
- rocksdb::Slice upper_bound(upper_bound_key);
-
- rocksdb::Iterator* iter = store->scan(symlink_prefix_key, &upper_bound);
- while(iter->Valid() && iter->key().starts_with(symlink_prefix_key)) {
- std::vector<std::string> parts;
- StringUtils::split(iter->key().ToString(), parts, symlink_prefix_key);
- collection_symlinks[parts[0]] = iter->value().ToString();
- iter->Next();
- }
- delete iter;
-
// load presets
std::string preset_prefix_key = std::string(PRESET_PREFIX) + "_";
diff --git a/src/filter_result_iterator.cpp b/src/filter_result_iterator.cpp
index 76f8a4f0..033ed005 100644
--- a/src/filter_result_iterator.cpp
+++ b/src/filter_result_iterator.cpp
@@ -652,13 +652,16 @@ void filter_result_iterator_t::init() {
if (is_referenced_filter) {
// Apply filter on referenced collection and get the sequence ids of current collection from the filtered documents.
auto& cm = CollectionManager::get_instance();
- auto const& ref_collection_name = a_filter.referenced_collection_name;
+ auto ref_collection_name = a_filter.referenced_collection_name;
auto ref_collection = cm.get_collection(ref_collection_name);
if (ref_collection == nullptr) {
status = Option<bool>(400, "Referenced collection `" + ref_collection_name + "` not found.");
validity = invalid;
return;
}
+ // `CollectionManager::get_collection` accounts for collection alias being used and provides pointer to the
+ // original collection.
+ ref_collection_name = ref_collection->name;
auto coll = cm.get_collection(collection_name);
bool is_referenced = coll->referenced_in.count(ref_collection_name) > 0,
diff --git a/test/collection_join_test.cpp b/test/collection_join_test.cpp
index d08179be..84d593cf 100644
--- a/test/collection_join_test.cpp
+++ b/test/collection_join_test.cpp
@@ -14,9 +14,9 @@ protected:
std::vector<std::string> query_fields;
std::vector<sort_by> sort_fields;
+ std::string state_dir_path = "/tmp/typesense_test/collection_join";
void setupCollection() {
- std::string state_dir_path = "/tmp/typesense_test/collection_join";
LOG(INFO) << "Truncating and creating: " << state_dir_path;
system(("rm -rf "+state_dir_path+" && mkdir -p "+state_dir_path).c_str());
@@ -2612,6 +2612,7 @@ TEST_F(CollectionJoinTest, IncludeExcludeFieldsByReference) {
{"filter_by", "$Customers(customer_id:=customer_a && product_price:<100)"},
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
nlohmann::json res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(1, res_obj["found"].get<size_t>());
@@ -2640,6 +2641,7 @@ TEST_F(CollectionJoinTest, IncludeExcludeFieldsByReference) {
{"include_fields", "*, $Customers(*:nest_array) as Customers"}
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(1, res_obj["found"].get<size_t>());
@@ -3908,6 +3910,7 @@ TEST_F(CollectionJoinTest, CascadeDeletion) {
{"q", "*"},
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(4, res_obj["found"].get<size_t>());
@@ -3921,6 +3924,7 @@ TEST_F(CollectionJoinTest, CascadeDeletion) {
{"q", "*"},
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(2, res_obj["found"].get<size_t>());
@@ -3934,6 +3938,7 @@ TEST_F(CollectionJoinTest, CascadeDeletion) {
{"q", "*"},
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(1, res_obj["found"].get<size_t>());
@@ -3944,6 +3949,7 @@ TEST_F(CollectionJoinTest, CascadeDeletion) {
{"q", "*"},
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(2, res_obj["found"].get<size_t>());
@@ -3967,6 +3973,7 @@ TEST_F(CollectionJoinTest, CascadeDeletion) {
{"q", "*"},
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(1, res_obj["found"].get<size_t>());
@@ -4758,7 +4765,7 @@ TEST_F(CollectionJoinTest, FilterByReferenceAlias) {
"name": "Products",
"fields": [
{"name": "product_id", "type": "string"},
- {"name": "product_name", "type": "string", "infix": true},
+ {"name": "product_name", "type": "string", "sort": true},
{"name": "product_description", "type": "string"},
{"name": "embedding", "type":"float[]", "embed":{"from": ["product_description"], "model_config": {"model_name": "ts/e5-small"}}},
{"name": "rating", "type": "int32"}
@@ -4840,7 +4847,7 @@ TEST_F(CollectionJoinTest, FilterByReferenceAlias) {
auto symlink_op = collectionManager.upsert_symlink("Products_alias", "Products");
ASSERT_TRUE(symlink_op.ok());
- symlink_op = collectionManager.upsert_symlink("$Customers_alias", "$Customers");
+ symlink_op = collectionManager.upsert_symlink("Customers_alias", "Customers");
ASSERT_TRUE(symlink_op.ok());
std::map<std::string, std::string> req_params = {
@@ -4855,6 +4862,7 @@ TEST_F(CollectionJoinTest, FilterByReferenceAlias) {
std::chrono::system_clock::now().time_since_epoch()).count();
auto search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
nlohmann::json res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(1, res_obj["found"].get<size_t>());
@@ -4882,6 +4890,7 @@ TEST_F(CollectionJoinTest, FilterByReferenceAlias) {
{"filter_by", "$Customers_alias(customer_id:=customer_a && product_price:<100)"},
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(1, res_obj["found"].get<size_t>());
@@ -4895,12 +4904,12 @@ TEST_F(CollectionJoinTest, FilterByReferenceAlias) {
ASSERT_EQ(1, res_obj["hits"][0]["document"].count("embedding"));
ASSERT_EQ(1, res_obj["hits"][0]["document"].count("rating"));
// Default strategy of reference includes is nest. No alias was provided, collection name becomes the field name.
- ASSERT_EQ(5, res_obj["hits"][0]["document"]["Customers"].size());
- ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers"].count("customer_id"));
- ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers"].count("customer_name"));
- 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(1, res_obj["hits"][0]["document"]["Customers"].count("product_price"));
+ ASSERT_EQ(5, res_obj["hits"][0]["document"]["Customers_alias"].size());
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("customer_id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("customer_name"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("product_id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("product_price"));
req_params = {
{"collection", "Products_alias"},
@@ -4909,6 +4918,7 @@ TEST_F(CollectionJoinTest, FilterByReferenceAlias) {
{"filter_by", "$Customers_alias(customer_id:=customer_a && product_price:<100)"},
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(1, res_obj["found"].get<size_t>());
@@ -4922,12 +4932,80 @@ TEST_F(CollectionJoinTest, FilterByReferenceAlias) {
ASSERT_EQ(1, res_obj["hits"][0]["document"].count("embedding"));
ASSERT_EQ(1, res_obj["hits"][0]["document"].count("rating"));
// Default strategy of reference includes is nest. No alias was provided, collection name becomes the field name.
- ASSERT_EQ(5, res_obj["hits"][0]["document"]["Customers"].size());
- ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers"].count("customer_id"));
- ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers"].count("customer_name"));
- 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(1, res_obj["hits"][0]["document"]["Customers"].count("product_price"));
+ ASSERT_EQ(5, res_obj["hits"][0]["document"]["Customers_alias"].size());
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("customer_id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("customer_name"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("product_id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("product_price"));
+
+ req_params = {
+ {"collection", "Products_alias"},
+ {"q", "*"},
+ {"query_by", "product_name"},
+ {"filter_by", "$Customers_alias(customer_id:=customer_a && product_price:<100)"},
+ {"include_fields", "product_name, $Customers_alias(product_id, product_price)"},
+ {"exclude_fields", "$Customers_alias(product_id)"}
+ };
+ search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
+
+ res_obj = nlohmann::json::parse(json_res);
+ ASSERT_EQ(1, res_obj["found"].get<size_t>());
+ ASSERT_EQ(1, res_obj["hits"].size());
+ ASSERT_EQ(2, res_obj["hits"][0]["document"].size());
+ ASSERT_EQ(1, res_obj["hits"][0]["document"].count("product_name"));
+ // Default strategy of reference includes is nest. No alias was provided, collection name becomes the field name.
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].size());
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("product_price"));
+
+ req_params = {
+ {"collection", "Products_alias"},
+ {"q", "*"},
+ {"query_by", "product_name"},
+ {"filter_by", "$Customers_alias(customer_id:=customer_a)"},
+ {"include_fields", "product_name, $Customers_alias(product_id, product_price)"},
+ {"exclude_fields", "$Customers_alias(product_id)"},
+ {"sort_by", "$Customers_alias(product_price: desc)"}
+ };
+ search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
+
+ res_obj = nlohmann::json::parse(json_res);
+ ASSERT_EQ(2, res_obj["found"].get<size_t>());
+ ASSERT_EQ(2, res_obj["hits"].size());
+ ASSERT_EQ(2, res_obj["hits"][0]["document"].size());
+ ASSERT_EQ(1, res_obj["hits"][0]["document"].count("product_name"));
+ ASSERT_EQ("shampoo", res_obj["hits"][0]["document"]["product_name"]);
+ ASSERT_EQ(1, res_obj["hits"][0]["document"].count("Customers_alias"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("product_price"));
+ ASSERT_EQ(143, res_obj["hits"][0]["document"]["Customers_alias"]["product_price"]);
+
+ ASSERT_EQ(2, res_obj["hits"][1]["document"].size());
+ ASSERT_EQ(1, res_obj["hits"][1]["document"].count("product_name"));
+ ASSERT_EQ("soap", res_obj["hits"][1]["document"]["product_name"]);
+ ASSERT_EQ(1, res_obj["hits"][1]["document"].count("Customers_alias"));
+ ASSERT_EQ(1, res_obj["hits"][1]["document"]["Customers_alias"].count("product_price"));
+ ASSERT_EQ(73.5, res_obj["hits"][1]["document"]["Customers_alias"]["product_price"]);
+
+ req_params = {
+ {"collection", "Customers"},
+ {"q", "*"},
+ {"filter_by", "customer_name:= [Joe, Dan] && product_price:<100"},
+ {"include_fields", "$Products_alias(product_name:merge), product_price"},
+ {"sort_by", "$Products_alias(product_name:desc)"},
+ };
+ search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
+
+ res_obj = nlohmann::json::parse(json_res);
+ ASSERT_EQ(2, res_obj["found"].get<size_t>());
+ ASSERT_EQ(2, res_obj["hits"].size());
+ ASSERT_EQ(2, res_obj["hits"][0]["document"].size());
+ ASSERT_EQ("soap", res_obj["hits"][0]["document"].at("product_name"));
+ ASSERT_EQ(73.5, res_obj["hits"][0]["document"].at("product_price"));
+ ASSERT_EQ("shampoo", res_obj["hits"][1]["document"].at("product_name"));
+ ASSERT_EQ(75, res_obj["hits"][1]["document"].at("product_price"));
collectionManager.drop_collection("Customers");
@@ -4982,9 +5060,10 @@ TEST_F(CollectionJoinTest, FilterByReferenceAlias) {
{"collection", "Products"},
{"q", "*"},
{"query_by", "product_name"},
- {"filter_by", "$Customers(customer_id:=customer_a && product_price:<100)"},
+ {"filter_by", "$Customers_alias(customer_id:=customer_a && product_price:<100)"},
};
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
res_obj = nlohmann::json::parse(json_res);
ASSERT_EQ(1, res_obj["found"].get<size_t>());
@@ -4998,12 +5077,57 @@ TEST_F(CollectionJoinTest, FilterByReferenceAlias) {
ASSERT_EQ(1, res_obj["hits"][0]["document"].count("embedding"));
ASSERT_EQ(1, res_obj["hits"][0]["document"].count("rating"));
// Default strategy of reference includes is nest. No alias was provided, collection name becomes the field name.
- ASSERT_EQ(5, res_obj["hits"][0]["document"]["Customers"].size());
- ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers"].count("customer_id"));
- ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers"].count("customer_name"));
- 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(1, res_obj["hits"][0]["document"]["Customers"].count("product_price"));
+ ASSERT_EQ(5, res_obj["hits"][0]["document"]["Customers_alias"].size());
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("customer_id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("customer_name"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("product_id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("product_price"));
+
+ // recreate collection manager to ensure that it initializes `referenced_in` correctly.
+ collectionManager.dispose();
+ delete store;
+
+ store = new Store(state_dir_path);
+ collectionManager.init(store, 1.0, "auth_key", quit);
+ auto load_op = collectionManager.load(8, 1000);
+
+ if(!load_op.ok()) {
+ LOG(ERROR) << load_op.error();
+ }
+ ASSERT_TRUE(load_op.ok());
+
+ // Reference field of Customers collection is referencing `Products_alias.product_id`. Alias resolution should happen
+ // in `CollectionManager::load`.
+ ASSERT_TRUE(collectionManager.get_collection("Products")->is_referenced_in("Customers"));
+
+ req_params = {
+ {"collection", "Products"},
+ {"q", "*"},
+ {"query_by", "product_name"},
+ {"filter_by", "$Customers_alias(customer_id:=customer_a && product_price:<100)"},
+ };
+ search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
+
+ res_obj = nlohmann::json::parse(json_res);
+ ASSERT_EQ(1, res_obj["found"].get<size_t>());
+ ASSERT_EQ(1, res_obj["hits"].size());
+ // No fields are mentioned in `include_fields`, should include all fields of Products and Customers by default.
+ ASSERT_EQ(7, res_obj["hits"][0]["document"].size());
+ ASSERT_EQ(1, res_obj["hits"][0]["document"].count("id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"].count("product_id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"].count("product_name"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"].count("product_description"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"].count("embedding"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"].count("rating"));
+ // Default strategy of reference includes is nest. No alias was provided, collection name becomes the field name.
+ ASSERT_EQ(5, res_obj["hits"][0]["document"]["Customers_alias"].size());
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("customer_id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("customer_name"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("product_id"));
+ ASSERT_EQ(1, res_obj["hits"][0]["document"]["Customers_alias"].count("product_price"));
}
TEST_F(CollectionJoinTest, QueryByReference) {