mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 12:42:50 +08:00
Handle bad geo polygon vertices.
This commit is contained in:
parent
1db5a260dd
commit
da9a42f3f1
@ -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];
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user