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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Ensure that emplace allows non-optional field update.
Kishore Nallan31503f699f12
diff --git a/src/index.cpp b/src/index.cppindex ae0ee69e..770168d9 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -296,7 +296,7 @@ Option<uint32_t> Index::validate_index_in_memory(nlohmann::json& document, uint3bool missing_default_sort_field = (!default_sorting_field.empty() && document.count(default_sorting_field) == 0);- if(op != UPDATE && missing_default_sort_field) {+ if((op != UPDATE && op != EMPLACE) && missing_default_sort_field) {return Option<>(400, "Field `" + default_sorting_field + "` has been declared as a default sorting field, ""but is not found in the document.");}@@ -309,7 +309,7 @@ Option<uint32_t> Index::validate_index_in_memory(nlohmann::json& document, uint3continue;}- if((a_field.optional || op == UPDATE) && document.count(field_name) == 0) {+ if((a_field.optional || op == UPDATE || op == EMPLACE) && document.count(field_name) == 0) {continue;}@@ -320,7 +320,7 @@ Option<uint32_t> Index::validate_index_in_memory(nlohmann::json& document, uint3if(a_field.optional && document[field_name].is_null()) {// we will ignore `null` on an option field- if(op != UPDATE) {+ if(op != UPDATE && op != EMPLACE) {// for updates, the erasure is done later since we need to keep the key for overwritedocument.erase(field_name);}diff --git a/test/collection_test.cpp b/test/collection_test.cppindex 97993643..2a470070 100644--- a/test/collection_test.cpp+++ b/test/collection_test.cpp@@ -1250,7 +1250,7 @@ TEST_F(CollectionTest, ImportDocumentsEmplace) {Collection* coll1;std::vector<field> fields = {field("title", field_types::STRING, false, false),- field("points", field_types::INT32, false, true)+ field("points", field_types::INT32, false, false)};coll1 = collectionManager.get_collection("coll1").get();@@ -1328,7 +1328,7 @@ TEST_F(CollectionTest, ImportDocumentsEmplace) {ASSERT_EQ(1, import_results[1].size());ASSERT_EQ(1, import_results[1].size());- // can update individual document via "emplace"+ // can update individual document via "emplace" with only partial field (missing points)std::string doc_3_update = R"({"id": "3", "title": "The Superman"})";auto add_op = coll1->add(doc_3_update, EMPLACE);ASSERT_TRUE(add_op.ok());