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

Ignore the last geopoint of polygon if it is same as the first geopoint.

Harpreet Sangar3b75487a71cc
diff --git a/src/filter_result_iterator.cpp b/src/filter_result_iterator.cpp
index ba776090..766a4add 100644
--- a/src/filter_result_iterator.cpp
+++ b/src/filter_result_iterator.cpp
@@ -888,10 +888,16 @@ void filter_result_iterator_t::init() {
std::vector<S2Point> vertices;
double sum = 0.0;
- for (size_t point_index = 0; point_index < size_t(num_verts);
- point_index++) {
+ for (size_t point_index = 0; point_index < size_t(num_verts); point_index++) {
double lat = std::stod(filter_value_parts[point_index * 2]);
double lon = std::stod(filter_value_parts[point_index * 2 + 1]);
+ if (point_index + 1 == size_t(num_verts) &&
+ lat == std::stod(filter_value_parts[0]) &&
+ lon == std::stod(filter_value_parts[1])) {
+ // The last geopoint is same as the first one.
+ break;
+ }
+
S2Point vertex = S2LatLng::FromDegrees(lat, lon).ToPoint();
vertices.emplace_back(vertex);
}
diff --git a/test/geo_filtering_old_test.cpp b/test/geo_filtering_old_test.cpp
index d9754a21..3919cefc 100644
--- a/test/geo_filtering_old_test.cpp
+++ b/test/geo_filtering_old_test.cpp
@@ -448,8 +448,8 @@ TEST_F(GeoFilteringOldTest, GeoPolygonFiltering) {
search_op = coll1->search("*", {}, "loc: (10, 20, 11, 12, 14, 16, 10, 20)", {}, {}, {0}, 10, 1,
FREQUENCY);
- ASSERT_FALSE(search_op.ok());
- ASSERT_EQ("Polygon is invalid: Edge 3 is degenerate (duplicate vertex)", search_op.error());
+ ASSERT_TRUE(search_op.ok());
+ ASSERT_EQ(0, search_op.get()["found"].get<size_t>());
collectionManager.drop_collection("coll1");
}
diff --git a/test/geo_filtering_test.cpp b/test/geo_filtering_test.cpp
index 81342b55..b23466ec 100644
--- a/test/geo_filtering_test.cpp
+++ b/test/geo_filtering_test.cpp
@@ -484,13 +484,13 @@ TEST_F(GeoFilteringTest, GeoPolygonFiltering) {
search_op = coll1->search("*", {}, "loc: (10, 20, 11, 12, 14, 16, 10, 20)", {}, {}, {0}, 10, 1,
FREQUENCY);
- ASSERT_FALSE(search_op.ok());
- ASSERT_EQ("Polygon is invalid: Edge 3 is degenerate (duplicate vertex)", search_op.error());
+ ASSERT_TRUE(search_op.ok());
+ ASSERT_EQ(0, search_op.get()["found"].get<size_t>());
search_op = coll1->search("*", {}, "loc: [([10, 20, 30, 40, 50, 30]), ([10, 20, 11, 12, 14, 16, 10, 20])]", {}, {},
{0}, 10, 1, FREQUENCY);
- ASSERT_FALSE(search_op.ok());
- ASSERT_EQ("Polygon at position 2 is invalid: Edge 3 is degenerate (duplicate vertex)", search_op.error());
+ ASSERT_TRUE(search_op.ok());
+ ASSERT_EQ(0, search_op.get()["found"].get<size_t>());
collectionManager.drop_collection("coll1");
}