diff --git a/src/index.cpp b/src/index.cpp index f7ec0232..758770e5 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -492,6 +492,13 @@ void Index::validate_and_preprocess(Index *index, get_doc_changes(index_rec.operation, embedding_fields, index_rec.doc, index_rec.old_doc, index_rec.new_doc, index_rec.del_doc); + /*if(index_rec.seq_id == 0) { + LOG(INFO) << "index_rec.doc: " << index_rec.doc; + LOG(INFO) << "index_rec.old_doc: " << index_rec.old_doc; + LOG(INFO) << "index_rec.new_doc: " << index_rec.new_doc; + LOG(INFO) << "index_rec.del_doc: " << index_rec.del_doc; + }*/ + if(generate_embeddings) { for(auto& field: index_rec.doc.items()) { for(auto& embedding_field : embedding_fields) { @@ -7125,6 +7132,8 @@ void Index::get_doc_changes(const index_operation_t op, const tsl::htrie_mapadd(doc1.dump(), UPSERT); + ASSERT_TRUE(add_op.ok()); + + auto results = coll1->search("alpha", {"title"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}).get(); + ASSERT_EQ(1, results["found"].get()); + ASSERT_EQ(3, results["hits"][0]["document"].size()); // id, title, status + ASSERT_EQ(1, results["hits"][0]["document"]["status"].size()); + + results = coll1->search("foo", {"status"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}).get(); + ASSERT_EQ(1, results["found"].get()); + + // upsert again with null value + doc1 = R"({ + "id": "0", + "title": "Title Alpha", + "status": {"name": null} + })"_json; + + add_op = coll1->add(doc1.dump(), UPSERT); + ASSERT_TRUE(add_op.ok()); + + results = coll1->search("alpha", {"title"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}).get(); + ASSERT_EQ(1, results["found"].get()); + ASSERT_EQ(3, results["hits"][0]["document"].size()); // id, title, status + ASSERT_EQ(0, results["hits"][0]["document"]["status"].size()); + + results = coll1->search("foo", {"status"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}).get(); + ASSERT_EQ(0, results["found"].get()); +} + TEST_F(CollectionNestedFieldsTest, EmplaceWithMissingArrayValueOnOptionalField) { nlohmann::json schema = R"({ "name": "coll1",