mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-29 16:24:26 +01:00
comments the geoboundingbox + forbid the usage of the lexeme method which could introduce bugs
This commit is contained in:
parent
fcb09ccc3d
commit
d27007005e
@ -88,10 +88,15 @@ impl<'a> Token<'a> {
|
|||||||
Self { span, value }
|
Self { span, value }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the string contained in the span of the `Token`.
|
||||||
|
/// This is only useful in the tests. You should always use
|
||||||
|
/// the value.
|
||||||
|
#[cfg(test)]
|
||||||
pub fn lexeme(&self) -> &str {
|
pub fn lexeme(&self) -> &str {
|
||||||
&self.span
|
&self.span
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the string contained in the token.
|
||||||
pub fn value(&self) -> &str {
|
pub fn value(&self) -> &str {
|
||||||
self.value.as_ref().map_or(&self.span, |value| value)
|
self.value.as_ref().map_or(&self.span, |value| value)
|
||||||
}
|
}
|
||||||
|
@ -294,7 +294,7 @@ impl<'a> Filter<'a> {
|
|||||||
Ok(RoaringBitmap::new())
|
Ok(RoaringBitmap::new())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match fid.lexeme() {
|
match fid.value() {
|
||||||
attribute @ "_geo" => {
|
attribute @ "_geo" => {
|
||||||
Err(fid.as_external_error(FilterError::BadGeo(attribute)))?
|
Err(fid.as_external_error(FilterError::BadGeo(attribute)))?
|
||||||
}
|
}
|
||||||
@ -412,6 +412,12 @@ impl<'a> Filter<'a> {
|
|||||||
.as_external_error(FilterError::BadGeoLng(bottom_right[1])))?;
|
.as_external_error(FilterError::BadGeoLng(bottom_right[1])))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instead of writing a custom `GeoBoundingBox` filter we're simply going to re-use the range
|
||||||
|
// filter to create the following filter;
|
||||||
|
// `_geo.lat {top_left[0]} TO {bottom_right[0]} AND _geo.lng {top_left[1]} TO {bottom_right[1]}`
|
||||||
|
// As we can see, we need to use a bunch of tokens that doesn't exists in the original filter,
|
||||||
|
// thus we're going to create tokens that points to a random spans but contains our text.
|
||||||
|
|
||||||
let geo_lat_token =
|
let geo_lat_token =
|
||||||
Token::new(top_left_point[0].original_span(), Some("_geo.lat".to_string()));
|
Token::new(top_left_point[0].original_span(), Some("_geo.lat".to_string()));
|
||||||
|
|
||||||
@ -432,6 +438,11 @@ impl<'a> Filter<'a> {
|
|||||||
let geo_lng_token =
|
let geo_lng_token =
|
||||||
Token::new(top_left_point[1].original_span(), Some("_geo.lng".to_string()));
|
Token::new(top_left_point[1].original_span(), Some("_geo.lng".to_string()));
|
||||||
let selected_lng = if top_left[1] > bottom_right[1] {
|
let selected_lng = if top_left[1] > bottom_right[1] {
|
||||||
|
// In this case the bounding box is wrapping around the earth (going from 180 to -180).
|
||||||
|
// We need to update the lng part of the filter from;
|
||||||
|
// `_geo.lng {top_left[1]} TO {bottom_right[1]}` to
|
||||||
|
// `_geo.lng {top_left[1]} TO 180 AND _geo.lng -180 TO {bottom_right[1]}`
|
||||||
|
|
||||||
let min_lng_token = Token::new(
|
let min_lng_token = Token::new(
|
||||||
top_left_point[1].original_span(),
|
top_left_point[1].original_span(),
|
||||||
Some("-180.0".to_string()),
|
Some("-180.0".to_string()),
|
||||||
|
Loading…
Reference in New Issue
Block a user