mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 12:42:50 +08:00
Add test for a bug which returned null values for nested fields.
This commit is contained in:
parent
0b904a3d6b
commit
a321e3622e
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user