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

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

Kishore Nallana321e3622e7c
diff --git a/test/collection_nested_fields_test.cpp b/test/collection_nested_fields_test.cpp
index 9693e08d..e50cf0e2 100644
--- a/test/collection_nested_fields_test.cpp
+++ b/test/collection_nested_fields_test.cpp
@@ -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",