Handle bad geo polygon vertices.

This commit is contained in:
Kishore Nallan 2022-01-16 12:44:45 +05:30
parent 1db5a260dd
commit da9a42f3f1
3 changed files with 29 additions and 2 deletions

View File

@ -1396,7 +1396,15 @@ void Index::do_filtering(uint32_t*& filter_ids, uint32_t& filter_ids_length,
std::reverse(vertices.begin(), vertices.end());
}
query_region = new S2Loop(vertices);
auto loop = new S2Loop(vertices, S2Debug::DISABLE);
S2Error error;
if (loop->FindValidationError(&error)) {
LOG(ERROR) << "Query vertex is bad, skipping. Error: " << error;
delete loop;
continue;
} else {
query_region = loop;
}
} else {
double radius = std::stof(filter_value_parts[2]);
const auto& unit = filter_value_parts[3];

View File

@ -632,6 +632,12 @@ TEST_F(CollectionManagerTest, ParseSortByClause) {
ASSERT_EQ("location(48.853, 2.344, exclude_radius: 2mi)", sort_fields[0].name);
ASSERT_STREQ("ASC", sort_fields[0].order.c_str());
sort_fields.clear();
sort_by_parsed = CollectionManager::parse_sort_by_str(" location(48.853, 2.344, precision: 2mi):asc,popularity:desc", sort_fields);
ASSERT_TRUE(sort_by_parsed);
ASSERT_EQ("location(48.853, 2.344, precision: 2mi)", sort_fields[0].name);
ASSERT_STREQ("ASC", sort_fields[0].order.c_str());
sort_fields.clear();
sort_by_parsed = CollectionManager::parse_sort_by_str(" _text_match(buckets: 10):ASC, points:desc ", sort_fields);
ASSERT_TRUE(sort_by_parsed);

View File

@ -778,10 +778,23 @@ TEST_F(CollectionSortingTest, GeoPointSortingWithExcludeRadius) {
ASSERT_STREQ(expected_ids[i].c_str(), results["hits"][i]["document"]["id"].get<std::string>().c_str());
}
geo_sort_fields = { sort_by("loc(32.24348, 77.1893, precision: 2mi)", "ASC") };
auto res_op = coll1->search("*", {}, "loc: (32.24348, 77.1893, 20 km)",
{}, geo_sort_fields, {0}, 10, 1, FREQUENCY);
ASSERT_TRUE(res_op.ok());
// bad vertex -- Edge 0 is degenerate (duplicate vertex)
geo_sort_fields = { sort_by("loc(28.7040592, 77.10249019999999)", "ASC") };
res_op = coll1->search("*", {}, "loc: (28.7040592, 77.10249019999999, 28.7040592, "
"77.10249019999999, 28.7040592, 77.10249019999999, 28.7040592, 77.10249019999999)",
{}, geo_sort_fields, {0}, 10, 1, FREQUENCY);
ASSERT_TRUE(res_op.ok());
ASSERT_EQ(0, res_op.get()["found"].get<size_t>());
// badly formatted exclusion filter
geo_sort_fields = { sort_by("loc(32.24348, 77.1893, exclude_radius 1 km)", "ASC") };
auto res_op = coll1->search("*", {}, "loc: (32.24348, 77.1893, 20 km)",
res_op = coll1->search("*", {}, "loc: (32.24348, 77.1893, 20 km)",
{}, geo_sort_fields, {0}, 10, 1, FREQUENCY);
ASSERT_FALSE(res_op.ok());