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
Allow empty first value for type detected fields.
Kishore Nallana59f41960fd8
diff --git a/src/collection.cpp b/src/collection.cppindex 893a4ed6..966955e6 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -2414,6 +2414,11 @@ Option<bool> Collection::check_and_update_schema(nlohmann::json& document, constcontinue;}+ if(kv.value().is_array() && kv.value().empty()) {+ kv++;+ continue;+ }+if(dirty_values == DIRTY_VALUES::REJECT || dirty_values == DIRTY_VALUES::COERCE_OR_REJECT) {return Option<bool>(400, "Type of field `" + kv.key() + "` is invalid.");} else {diff --git a/test/collection_all_fields_test.cpp b/test/collection_all_fields_test.cppindex ba73c501..afaa94f2 100644--- a/test/collection_all_fields_test.cpp+++ b/test/collection_all_fields_test.cpp@@ -423,8 +423,7 @@ TEST_F(CollectionAllFieldsTest, StringifyAllValues) {doc["single_int"] = "200";add_op = coll1->add(doc.dump(), CREATE, "", DIRTY_VALUES::REJECT);- ASSERT_FALSE(add_op.ok());- ASSERT_EQ("Type of field `int_values_2` is invalid.", add_op.error());+ ASSERT_TRUE(add_op.ok());collectionManager.drop_collection("coll1");}@@ -1436,3 +1435,27 @@ TEST_F(CollectionAllFieldsTest, NullValueArrayUpdate) {collectionManager.drop_collection("coll1");}++TEST_F(CollectionAllFieldsTest, EmptyArrayShouldBeAcceptedAsFirstValueOfAutoField) {+ Collection *coll1;++ std::vector<field> fields = {field(".*", field_types::AUTO, false, true)};++ coll1 = collectionManager.get_collection("coll1").get();+ if (coll1 == nullptr) {+ auto op = collectionManager.create_collection("coll1", 1, fields, "",+ 0, field_types::AUTO);+ ASSERT_TRUE(op.ok());+ coll1 = op.get();+ }++ nlohmann::json doc;+ doc["company_name"] = "Amazon Inc.";+ doc["tags"] = nlohmann::json::array();+ doc["country"] = "USA";++ auto add_op = coll1->add(doc.dump(), CREATE);+ ASSERT_TRUE(add_op.ok());++ collectionManager.drop_collection("coll1");+}diff --git a/test/collection_specific_test.cpp b/test/collection_specific_test.cppindex c3d4d977..624811a4 100644--- a/test/collection_specific_test.cpp+++ b/test/collection_specific_test.cpp@@ -2020,3 +2020,25 @@ TEST_F(CollectionSpecificTest, DuplicateFieldsNotAllowed) {ASSERT_TRUE(create_op.ok());}++TEST_F(CollectionSpecificTest, EmptyArrayShouldBeAcceptedAsFirstValue) {+ Collection *coll1;++ std::vector<field> fields = {field("tags", field_types::STRING_ARRAY, false, true)};++ coll1 = collectionManager.get_collection("coll1").get();+ if (coll1 == nullptr) {+ auto op = collectionManager.create_collection("coll1", 1, fields, "");+ ASSERT_TRUE(op.ok());+ coll1 = op.get();+ }++ nlohmann::json doc;+ doc["company_name"] = "Amazon Inc.";+ doc["tags"] = nlohmann::json::array();++ auto add_op = coll1->add(doc.dump(), CREATE);+ ASSERT_TRUE(add_op.ok());++ collectionManager.drop_collection("coll1");+}