Add test for a bug which returned null values for nested fields.

This commit is contained in:
Kishore Nallan 2023-04-28 16:04:22 +05:30
parent 0b904a3d6b
commit a321e3622e

View File

@ -2406,6 +2406,33 @@ TEST_F(CollectionNestedFieldsTest, FieldsWithDotsButNotNested) {
results["hits"][0]["highlight"]["name.first"]["snippet"].get<std::string>());
}
TEST_F(CollectionNestedFieldsTest, NullValuesWithExplicitSchema) {
nlohmann::json schema = R"({
"name": "coll1",
"enable_nested_fields": true,
"fields": [
{"name": "name", "type": "object"},
{"name": "name.first", "type": "string"},
{"name": "name.last", "type": "string", "optional": true}
]
})"_json;
auto op = collectionManager.create_collection(schema);
ASSERT_TRUE(op.ok());
Collection* coll1 = op.get();
auto doc1 = R"({
"name": {"last": null, "first": "Jack"}
})"_json;
auto add_op = coll1->add(doc1.dump(), CREATE);
ASSERT_TRUE(add_op.ok());
auto results = coll1->search("jack", {"name.first"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}).get();
ASSERT_EQ(1, results["found"].get<size_t>());
ASSERT_EQ(2, results["hits"][0]["document"].size()); // id, name
}
TEST_F(CollectionNestedFieldsTest, UpdateNestedDocument) {
nlohmann::json schema = R"({
"name": "coll1",