mirror of
https://github.com/typesense/typesense.git
synced 2025-05-15 19:06:48 +08:00
Allow large float values for default_sorting_field
.
Fixes https://github.com/typesense/typesense/issues/94
This commit is contained in:
parent
412efbb500
commit
5de270f4ae
@ -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.");
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 }
|
||||
|
Loading…
x
Reference in New Issue
Block a user