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

Allow large float values for `default_sorting_field`.

kishorenc5de270f4ae78
diff --git a/src/index.cpp b/src/index.cpp
index c7e5ca32..200f0847 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -157,12 +157,12 @@ Option<uint32_t> Index::validate_index_in_memory(const nlohmann::json &document,
return Option<>(400, "Default sorting field `" + default_sorting_field + "` must be of type int32 or float.");
}
- if(document[default_sorting_field].is_number_integer() &&
+ if(search_schema.at(default_sorting_field).is_single_integer() &&
document[default_sorting_field].get<int64_t>() > std::numeric_limits<int32_t>::max()) {
return Option<>(400, "Default sorting field `" + default_sorting_field + "` exceeds maximum value of an int32.");
}
- if(document[default_sorting_field].is_number_float() &&
+ if(search_schema.at(default_sorting_field).is_single_float() &&
document[default_sorting_field].get<float>() > std::numeric_limits<float>::max()) {
return Option<>(400, "Default sorting field `" + default_sorting_field + "` exceeds maximum value of a float.");
}
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index 3a8405af..b3af6125 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -1083,7 +1083,14 @@ TEST_F(CollectionTest, FilterOnNumericFields) {
coll_array_fields = collectionManager.get_collection("coll_array_fields");
if(coll_array_fields == nullptr) {
- coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, "age").get();
+ // ensure that default_sorting_field is a non-array numerical field
+ auto coll_op = collectionManager.create_collection("coll_array_fields", fields, "years");
+ ASSERT_EQ(false, coll_op.ok());
+ ASSERT_STREQ("Default sorting field `years` must be of type int32 or float.", coll_op.error().c_str());
+
+ // let's try again properly
+ coll_op = collectionManager.create_collection("coll_array_fields", fields, "age");
+ coll_array_fields = coll_op.get();
}
std::string json_line;
diff --git a/test/float_documents.jsonl b/test/float_documents.jsonl
index 9ae520f7..b6b04cd3 100644
--- a/test/float_documents.jsonl
+++ b/test/float_documents.jsonl
@@ -1,6 +1,6 @@
{"title": "Jeremy Howard", "score": 1.09, "average": 1.45}
{"title": "Jeremy Howard", "score": -9.998, "average": -2.408 }
-{"title": "Jeremy Howard", "score": 7.812, "average": 0.001 }
+{"title": "Jeremy Howard", "score": 1582186644000, "average": 0.001 }
{"title": "Jeremy Howard", "score": 0.0, "average": 11.533 }
{"title": "Jeremy Howard", "score": -9.999, "average": -11.38 }
{"title": "Jeremy Howard", "score": -9.999, "average": 300 }