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
Return error when `sort: false` is set for geopoint/geopoint[] field. (#1872)
Harpreet Sangarb46c72572b32
diff --git a/src/field.cpp b/src/field.cppindex 548db2d9..9bbb3f34 100644--- a/src/field.cpp+++ b/src/field.cpp@@ -208,6 +208,11 @@ Option<bool> field::json_field_to_field(bool enable_nested_fields, nlohmann::jso} else {field_json[fields::sort] = false;}+ } else if (!field_json[fields::sort].get<bool>() &&+ (field_json["type"] == field_types::GEOPOINT || field_json["type"] == field_types::GEOPOINT_ARRAY)) {+ return Option<bool>(400, std::string("The `sort` property of the field `") +=+ field_json[fields::name].get<std::string>() += "` having `" + field_json["type"].get<std::string>() +=+ "` type cannot be `false`. The sort index is used during GeoSearch.");}if(field_json.count(fields::infix) == 0) {diff --git a/test/collection_all_fields_test.cpp b/test/collection_all_fields_test.cppindex 3fc33f92..faa47193 100644--- a/test/collection_all_fields_test.cpp+++ b/test/collection_all_fields_test.cpp@@ -1774,3 +1774,30 @@ TEST_F(CollectionAllFieldsTest, InvalidstemValue) {ASSERT_EQ("The `stem` property is only allowed for string and string[] fields.", obj_coll_op.error());}+TEST_F(CollectionAllFieldsTest, GeopointSortValue) {+ nlohmann::json schema = R"({+ "name": "test",+ "fields": [+ {"name": "geo", "type": "geopoint", "sort": false}+ ]+ })"_json;++ auto create_op = collectionManager.create_collection(schema);+ ASSERT_FALSE(create_op.ok());+ ASSERT_EQ("The `sort` property of the field `geo` having `geopoint` type cannot be `false`."+ " The sort index is used during GeoSearch.", create_op.error());++ schema = R"({+ "name": "test",+ "fields": [+ {"name": "geo_array", "type": "geopoint[]", "sort": false}+ ]+ })"_json;++ create_op = collectionManager.create_collection(schema);+ ASSERT_FALSE(create_op.ok());+ ASSERT_EQ("The `sort` property of the field `geo_array` having `geopoint[]` type cannot be `false`."+ " The sort index is used during GeoSearch.", create_op.error());++}+diff --git a/test/geo_filtering_old_test.cpp b/test/geo_filtering_old_test.cppindex 3919cefc..2afd3c5e 100644--- a/test/geo_filtering_old_test.cpp+++ b/test/geo_filtering_old_test.cpp@@ -512,7 +512,7 @@ TEST_F(GeoFilteringOldTest, GeoPointFilteringWithNonSortableLocationField) {"name": "coll1","fields": [{"name": "title", "type": "string", "sort": false},- {"name": "loc", "type": "geopoint", "sort": false},+ {"name": "loc", "type": "geopoint", "sort": true},{"name": "points", "type": "int32", "sort": false}]})"_json;diff --git a/test/geo_filtering_test.cpp b/test/geo_filtering_test.cppindex b23466ec..936546a4 100644--- a/test/geo_filtering_test.cpp+++ b/test/geo_filtering_test.cpp@@ -567,7 +567,7 @@ TEST_F(GeoFilteringTest, GeoPointFilteringWithNonSortableLocationField) {"name": "coll1","fields": [{"name": "title", "type": "string", "sort": false},- {"name": "loc", "type": "geopoint", "sort": false},+ {"name": "loc", "type": "geopoint", "sort": true},{"name": "points", "type": "int32", "sort": false}]})"_json;