review the filters errors

This commit is contained in:
Tamo
2025-09-17 16:26:24 +02:00
parent 8306c2b89c
commit 501e3816a8
4 changed files with 12 additions and 11 deletions

View File

@ -78,7 +78,7 @@ pub enum ErrorKind<'a> {
GeoRadiusArgumentCount(usize),
GeoBoundingBox,
GeoPolygon,
GeoPolygonTooFewPoints,
GeoPolygonNotEnoughPoints(usize),
GeoCoordinatesNotPair(usize),
MisusedGeoRadius,
MisusedGeoBoundingBox,
@ -213,8 +213,8 @@ impl Display for Error<'_> {
ErrorKind::GeoPolygon => {
writeln!(f, "The `_geoPolygon` filter doesn't match the expected format: `_geoPolygon([latitude, longitude], [latitude, longitude])`.")?
}
ErrorKind::GeoPolygonTooFewPoints => {
writeln!(f, "The `_geoPolygon` filter expects at least 2 points")?;
ErrorKind::GeoPolygonNotEnoughPoints(n) => {
writeln!(f, "The `_geoPolygon` filter expects at least 3 points but only {n} were specified")?;
}
ErrorKind::GeoCoordinatesNotPair(number) => {
writeln!(f, "Was expecting 2 coordinates but instead found {number}.")?

View File

@ -465,7 +465,7 @@ fn parse_geo_bounding_box(input: Span) -> IResult<FilterCondition> {
/// geoPolygon = "_geoPolygon([[" WS* float WS* "," WS* float WS* "],+])"
/// If we parse `_geoPolygon` we MUST parse the rest of the expression.
fn parse_geo_polygon(input: Span) -> IResult<FilterCondition> {
// we want to allow space BEFORE the _geoBoundingBox but not after
// we want to allow space BEFORE the _geoPolygon but not after
let (input, _) = tuple((multispace0, word_exact("_geoPolygon")))(input)?;
@ -481,9 +481,12 @@ fn parse_geo_polygon(input: Span) -> IResult<FilterCondition> {
)(input)
.map_cut(ErrorKind::GeoPolygon)?;
if args.len() < 2 {
if args.len() < 3 {
let context = args.last().and_then(|a| a.last()).unwrap_or(&input);
return Err(Error::failure_from_kind(*context, ErrorKind::GeoPolygonTooFewPoints));
return Err(Error::failure_from_kind(
*context,
ErrorKind::GeoPolygonNotEnoughPoints(args.len()),
));
}
if let Some(offending) = args.iter().find(|a| a.len() != 2) {

View File

@ -539,6 +539,7 @@ impl ErrorCode for milli::Error {
| cellulite::Error::CannotConvertLineToCell(_, _, _) => Code::Internal,
cellulite::Error::InvalidGeoJson(_) => Code::InvalidDocumentGeojsonField,
},
UserError::MalformedGeojson(_) => Code::InvalidDocumentGeojsonField,
}
}
}

View File

@ -699,12 +699,9 @@ impl<'a> Filter<'a> {
if index.is_geojson_filtering_enabled(rtxn)? {
let point = geo_types::Point::new(base_point[1], base_point[0]);
let result = index
.cellulite
.in_circle(rtxn, point, radius, resolution)
.map_err(InternalError::CelluliteError)?;
let result = index.cellulite.in_circle(rtxn, point, radius, resolution)?;
r2 = Some(RoaringBitmap::from_iter(result)); // TODO: Remove once we update roaring
r2 = Some(RoaringBitmap::from_iter(result)); // TODO: Remove once we update roaring in meilisearch
}
match (r1, r2) {