mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-18 18:56:25 +00:00
review the filters errors
This commit is contained in:
@ -78,7 +78,7 @@ pub enum ErrorKind<'a> {
|
|||||||
GeoRadiusArgumentCount(usize),
|
GeoRadiusArgumentCount(usize),
|
||||||
GeoBoundingBox,
|
GeoBoundingBox,
|
||||||
GeoPolygon,
|
GeoPolygon,
|
||||||
GeoPolygonTooFewPoints,
|
GeoPolygonNotEnoughPoints(usize),
|
||||||
GeoCoordinatesNotPair(usize),
|
GeoCoordinatesNotPair(usize),
|
||||||
MisusedGeoRadius,
|
MisusedGeoRadius,
|
||||||
MisusedGeoBoundingBox,
|
MisusedGeoBoundingBox,
|
||||||
@ -213,8 +213,8 @@ impl Display for Error<'_> {
|
|||||||
ErrorKind::GeoPolygon => {
|
ErrorKind::GeoPolygon => {
|
||||||
writeln!(f, "The `_geoPolygon` filter doesn't match the expected format: `_geoPolygon([latitude, longitude], [latitude, longitude])`.")?
|
writeln!(f, "The `_geoPolygon` filter doesn't match the expected format: `_geoPolygon([latitude, longitude], [latitude, longitude])`.")?
|
||||||
}
|
}
|
||||||
ErrorKind::GeoPolygonTooFewPoints => {
|
ErrorKind::GeoPolygonNotEnoughPoints(n) => {
|
||||||
writeln!(f, "The `_geoPolygon` filter expects at least 2 points")?;
|
writeln!(f, "The `_geoPolygon` filter expects at least 3 points but only {n} were specified")?;
|
||||||
}
|
}
|
||||||
ErrorKind::GeoCoordinatesNotPair(number) => {
|
ErrorKind::GeoCoordinatesNotPair(number) => {
|
||||||
writeln!(f, "Was expecting 2 coordinates but instead found {number}.")?
|
writeln!(f, "Was expecting 2 coordinates but instead found {number}.")?
|
||||||
|
@ -465,7 +465,7 @@ fn parse_geo_bounding_box(input: Span) -> IResult<FilterCondition> {
|
|||||||
/// geoPolygon = "_geoPolygon([[" WS* float WS* "," WS* float WS* "],+])"
|
/// geoPolygon = "_geoPolygon([[" WS* float WS* "," WS* float WS* "],+])"
|
||||||
/// If we parse `_geoPolygon` we MUST parse the rest of the expression.
|
/// If we parse `_geoPolygon` we MUST parse the rest of the expression.
|
||||||
fn parse_geo_polygon(input: Span) -> IResult<FilterCondition> {
|
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)?;
|
let (input, _) = tuple((multispace0, word_exact("_geoPolygon")))(input)?;
|
||||||
|
|
||||||
@ -481,9 +481,12 @@ fn parse_geo_polygon(input: Span) -> IResult<FilterCondition> {
|
|||||||
)(input)
|
)(input)
|
||||||
.map_cut(ErrorKind::GeoPolygon)?;
|
.map_cut(ErrorKind::GeoPolygon)?;
|
||||||
|
|
||||||
if args.len() < 2 {
|
if args.len() < 3 {
|
||||||
let context = args.last().and_then(|a| a.last()).unwrap_or(&input);
|
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) {
|
if let Some(offending) = args.iter().find(|a| a.len() != 2) {
|
||||||
|
@ -539,6 +539,7 @@ impl ErrorCode for milli::Error {
|
|||||||
| cellulite::Error::CannotConvertLineToCell(_, _, _) => Code::Internal,
|
| cellulite::Error::CannotConvertLineToCell(_, _, _) => Code::Internal,
|
||||||
cellulite::Error::InvalidGeoJson(_) => Code::InvalidDocumentGeojsonField,
|
cellulite::Error::InvalidGeoJson(_) => Code::InvalidDocumentGeojsonField,
|
||||||
},
|
},
|
||||||
|
UserError::MalformedGeojson(_) => Code::InvalidDocumentGeojsonField,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -699,12 +699,9 @@ impl<'a> Filter<'a> {
|
|||||||
if index.is_geojson_filtering_enabled(rtxn)? {
|
if index.is_geojson_filtering_enabled(rtxn)? {
|
||||||
let point = geo_types::Point::new(base_point[1], base_point[0]);
|
let point = geo_types::Point::new(base_point[1], base_point[0]);
|
||||||
|
|
||||||
let result = index
|
let result = index.cellulite.in_circle(rtxn, point, radius, resolution)?;
|
||||||
.cellulite
|
|
||||||
.in_circle(rtxn, point, radius, resolution)
|
|
||||||
.map_err(InternalError::CelluliteError)?;
|
|
||||||
|
|
||||||
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) {
|
match (r1, r2) {
|
||||||
|
Reference in New Issue
Block a user