Skip to content

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

Float array field should accept integer values.

kishorenc81dfe760094b
diff --git a/src/index.cpp b/src/index.cpp
index 590793c6..7e6f9ba1 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -295,7 +295,8 @@ Option<uint32_t> Index::validate_index_in_memory(const nlohmann::json &document,
return Option<>(400, "Field `" + field_name + "` must be a float array.");
}
- if(document[field_name].size() > 0 && !document[field_name][0].is_number_float()) {
+ if(document[field_name].size() > 0 && !document[field_name][0].is_number()) {
+ // allows integer to be passed to a float array field
return Option<>(400, "Field `" + field_name + "` must be a float array.");
}
} else if(field_pair.second.type == field_types::BOOL_ARRAY) {
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index cac9d715..358e1a57 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -1122,7 +1122,8 @@ TEST_F(CollectionTest, FilterOnFloatFields) {
std::string json_line;
while (std::getline(infile, json_line)) {
- coll_array_fields->add(json_line);
+ auto add_op = coll_array_fields->add(json_line);
+ ASSERT_TRUE(add_op.ok());
}
infile.close();
diff --git a/test/numeric_array_documents.jsonl b/test/numeric_array_documents.jsonl
index ae659381..6df3acd1 100644
--- a/test/numeric_array_documents.jsonl
+++ b/test/numeric_array_documents.jsonl
@@ -1,5 +1,5 @@
{"name": "Jeremy Howard", "top_3": [1.09, 1.88, 0.001], "rating": 1.09, "age": 24, "years": [2014, 2015, 2016], "timestamps": [1390354022, 1421890022, 1453426022], "tags": ["gold", "silver"]}
{"name": "Jeremy Howard", "top_3": [9.999, 8.89, 7.713], "rating": 9.999, "age": 44, "years": [2015, 2016], "timestamps": [1421890022, 1453426022], "tags": ["FINE PLATINUM"]}
{"name": "Jeremy Howard", "top_3": [7.812, 7.770, 6.66], "rating": 7.812, "age": 21, "years": [2016], "timestamps": [1453426022], "tags": ["bronze", "gold"]}
-{"name": "Jeremy Howard", "top_3": [0.0, 0.0, 0.0], "rating": 0.0, "age": 63, "years": [1981, 1985], "timestamps": [348974822, 475205222], "tags": ["silver"]}
+{"name": "Jeremy Howard", "top_3": [0, 0.0, 0.0], "rating": 0.0, "age": 63, "years": [1981, 1985], "timestamps": [348974822, 475205222], "tags": ["silver"]}
{"name": "Jeremy Howard", "top_3": [5.5, 5.431, 1.001], "rating": 5.5, "age": 32, "years": [1999, 2000, 2001, 2002], "timestamps": [916968422, 948504422, 980126822, 1011662822], "tags": ["silver", "gold", "bronze"]}
\ No newline at end of file