mirror of
https://github.com/typesense/typesense.git
synced 2025-05-20 13:42:26 +08:00
Update CollectionJoinTest, FilterByReferenceAlias
.
This commit is contained in:
parent
e13adbb0c2
commit
c74099091d
@ -4233,4 +4233,80 @@ TEST_F(CollectionJoinTest, FilterByReferenceAlias) {
|
||||
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"));
|
||||
|
||||
collectionManager.drop_collection("Customers");
|
||||
|
||||
// Alias in reference.
|
||||
schema_json =
|
||||
R"({
|
||||
"name": "Customers",
|
||||
"fields": [
|
||||
{"name": "customer_id", "type": "string"},
|
||||
{"name": "customer_name", "type": "string"},
|
||||
{"name": "product_price", "type": "float"},
|
||||
{"name": "product_id", "type": "string", "reference": "Products_alias.product_id"}
|
||||
]
|
||||
})"_json;
|
||||
documents = {
|
||||
R"({
|
||||
"customer_id": "customer_a",
|
||||
"customer_name": "Joe",
|
||||
"product_price": 143,
|
||||
"product_id": "product_a"
|
||||
})"_json,
|
||||
R"({
|
||||
"customer_id": "customer_a",
|
||||
"customer_name": "Joe",
|
||||
"product_price": 73.5,
|
||||
"product_id": "product_b"
|
||||
})"_json,
|
||||
R"({
|
||||
"customer_id": "customer_b",
|
||||
"customer_name": "Dan",
|
||||
"product_price": 75,
|
||||
"product_id": "product_a"
|
||||
})"_json,
|
||||
R"({
|
||||
"customer_id": "customer_b",
|
||||
"customer_name": "Dan",
|
||||
"product_price": 140,
|
||||
"product_id": "product_b"
|
||||
})"_json
|
||||
};
|
||||
collection_create_op = collectionManager.create_collection(schema_json);
|
||||
ASSERT_TRUE(collection_create_op.ok());
|
||||
for (auto const &json: documents) {
|
||||
auto add_op = collection_create_op.get()->add(json.dump());
|
||||
if (!add_op.ok()) {
|
||||
LOG(INFO) << add_op.error();
|
||||
}
|
||||
ASSERT_TRUE(add_op.ok());
|
||||
}
|
||||
|
||||
req_params = {
|
||||
{"collection", "Products"},
|
||||
{"q", "*"},
|
||||
{"query_by", "product_name"},
|
||||
{"filter_by", "$Customers(customer_id:=customer_a && product_price:<100)"},
|
||||
};
|
||||
search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
|
||||
|
||||
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"].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"));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user