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

Handle nan values for geo filter query.

Kishore Nallan25c5ae693189
diff --git a/src/field.cpp b/src/field.cpp
index 60a8695a..c6b7d5e0 100644
--- a/src/field.cpp
+++ b/src/field.cpp
@@ -41,6 +41,11 @@ Option<bool> filter::parse_geopoint_filter_value(std::string& raw_value,
if(!StringUtils::is_float(filter_values[0]) || !StringUtils::is_float(filter_values[1])) {
return Option<bool>(400, format_err_msg);
}
+
+ if(filter_values[0] == "nan" || filter_values[0] == "NaN" ||
+ filter_values[1] == "nan" || filter_values[1] == "NaN") {
+ return Option<bool>(400, format_err_msg);
+ }
}
if(is_polygon) {
diff --git a/test/collection_filtering_test.cpp b/test/collection_filtering_test.cpp
index 12ea5e66..1ad3c62c 100644
--- a/test/collection_filtering_test.cpp
+++ b/test/collection_filtering_test.cpp
@@ -1128,6 +1128,14 @@ TEST_F(CollectionFilteringTest, GeoPointFiltering) {
ASSERT_STREQ("5", results["hits"][1]["document"]["id"].get<std::string>().c_str());
ASSERT_STREQ("3", results["hits"][2]["document"]["id"].get<std::string>().c_str());
+ // when geo query had NaN
+ auto gop = coll1->search("*", {}, "loc: (NaN, nan, 1 mi)",
+ {}, {}, {0}, 10, 1, FREQUENCY);
+
+ ASSERT_FALSE(gop.ok());
+ ASSERT_EQ("Value of filter field `loc`: must be in the `(-44.50, 170.29, 0.75 km)` or "
+ "(56.33, -65.97, 23.82, -127.82) format.", gop.error());
+
// when geo field is formatted as string, show meaningful error
nlohmann::json bad_doc;
bad_doc["id"] = "1000";