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 an integer to be passed to a field defined as a float.
Kishore Nallanc1c7d493e502
diff --git a/src/collection.cpp b/src/collection.cppindex aca6bc9f..d15d919f 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -143,7 +143,7 @@ Option<uint32_t> Collection::validate_index_in_memory(const nlohmann::json &docureturn Option<>(400, "Field `" + field_name + "` must be an int64.");}} else if(field_pair.second.type == field_types::FLOAT) {- if(!document[field_name].is_number_float()) {+ if(!document[field_name].is_number()) { // allows integer to be passed to a float fieldreturn Option<>(400, "Field `" + field_name + "` must be a float.");}} else if(field_pair.second.type == field_types::STRING_ARRAY) {diff --git a/test/collection_test.cpp b/test/collection_test.cppindex 233e3888..64896ff6 100644--- a/test/collection_test.cpp+++ b/test/collection_test.cpp@@ -1446,6 +1446,29 @@ TEST_F(CollectionTest, IdFieldShouldBeAString) {collectionManager.drop_collection("coll1");}+TEST_F(CollectionTest, AnIntegerCanBePassedToAFloatField) {+ Collection *coll1;++ std::vector<field> fields = {field("name", field_types::STRING, false),+ field("average", field_types::FLOAT, false)};++ std::vector<sort_by> sort_fields = { sort_by("average", "DESC") };++ coll1 = collectionManager.get_collection("coll1");+ if(coll1 == nullptr) {+ coll1 = collectionManager.create_collection("coll1", fields).get();+ }++ nlohmann::json doc;+ doc["id"] = "101010";+ doc["name"] = "Jane";+ doc["average"] = 98;++ Option<std::string> inserted_id_op = coll1->add(doc.dump());+ EXPECT_TRUE(inserted_id_op.ok());+ collectionManager.drop_collection("coll1");+}+TEST_F(CollectionTest, DeletionOfADocument) {collectionManager.drop_collection("collection");