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
Validate object array reference helper field regardless of the value of `dirty_values`.
Harpreet Sangar7a5959f2872b
diff --git a/src/validator.cpp b/src/validator.cppindex 4785ff89..701264b0 100644--- a/src/validator.cpp+++ b/src/validator.cpp@@ -319,6 +319,16 @@ Option<uint32_t> validator_t::coerce_int64_t(const DIRTY_VALUES& dirty_values, cstd::string suffix = is_array ? "an array of" : "an";auto& item = is_array ? array_iter.value() : document[field_name];+ // Object array reference helper field. It's not provided by the user.+ if(is_array && a_field.nested && a_field.is_reference_helper) {+ // It's an array of two uint32_t values indicating the object index and referenced doc id respectively.+ if(item.size() != 2 || !item.at(0).is_number_unsigned() || !item.at(1).is_number_unsigned()) {+ return Option<>(400, "`" + field_name + "` object array reference helper field has wrong value `"+ + item.dump() + "`.");+ }+ return Option<uint32_t>(200);+ }+if(dirty_values == DIRTY_VALUES::REJECT) {if(a_field.nested && item.is_array()) {return Option<>(400, "Field `" + field_name + "` has an incorrect type. "@@ -359,13 +369,6 @@ Option<uint32_t> validator_t::coerce_int64_t(const DIRTY_VALUES& dirty_values, citem = std::atoll(item.get<std::string>().c_str());}- else if(is_array && a_field.nested && a_field.is_reference_helper) {- if(item.size() != 2 || !item.at(0).is_number() || !item.at(1).is_number()) {- return Option<>(400, "`" + field_name + "` object array reference helper field has wrong value `"- + item.dump() + "`.");- }- }-else {if(dirty_values == DIRTY_VALUES::COERCE_OR_DROP) {if(!a_field.optional) {diff --git a/test/collection_join_test.cpp b/test/collection_join_test.cppindex 7d280aac..e3e15354 100644--- a/test/collection_join_test.cpp+++ b/test/collection_join_test.cpp@@ -3044,7 +3044,7 @@ TEST_F(CollectionJoinTest, FilterByObjectReferenceField) {collection_create_op = collectionManager.create_collection(schema_json);ASSERT_TRUE(collection_create_op.ok());for (auto const &json: documents) {- auto add_op = collection_create_op.get()->add(json.dump());+ auto add_op = collection_create_op.get()->add(json.dump(), CREATE, "", DIRTY_VALUES::REJECT);if (!add_op.ok()) {LOG(INFO) << add_op.error();}