add a check on the fid in the geosearch

This commit is contained in:
Tamo 2021-10-22 18:08:18 +02:00
parent 3942b3732f
commit c8d03046bf
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69

View File

@ -309,7 +309,11 @@ impl<'a> Filter<'a> {
} }
FilterCondition::Empty => Ok(RoaringBitmap::new()), FilterCondition::Empty => Ok(RoaringBitmap::new()),
FilterCondition::GeoLowerThan { point, radius } => { FilterCondition::GeoLowerThan { point, radius } => {
let filterable_fields = index.fields_ids_map(rtxn)?;
if filterable_fields.id("_geo").is_some() {
let base_point = [parse(&point[0])?, parse(&point[1])?]; let base_point = [parse(&point[0])?, parse(&point[1])?];
// TODO TAMO: ensure lat is between -90 and 90
// TODO TAMO: ensure lng is between -180 and 180
let radius = parse(&radius)?; let radius = parse(&radius)?;
let rtree = match index.geo_rtree(rtxn)? { let rtree = match index.geo_rtree(rtxn)? {
Some(rtree) => rtree, Some(rtree) => rtree,
@ -324,7 +328,13 @@ impl<'a> Filter<'a> {
.map(|point| point.data) .map(|point| point.data)
.collect(); .collect();
return Ok(result); Ok(result)
} else {
// TODO TAMO: update the error message
return Err(UserError::InvalidFilter {
input: format!("You tried to use _geo in a filter, you probably wanted to use _geoRadius"),
})?;
}
} }
FilterCondition::GeoGreaterThan { point, radius } => { FilterCondition::GeoGreaterThan { point, radius } => {
let result = Self::evaluate( let result = Self::evaluate(
@ -334,7 +344,7 @@ impl<'a> Filter<'a> {
index, index,
)?; )?;
let geo_faceted_doc_ids = index.geo_faceted_documents_ids(rtxn)?; let geo_faceted_doc_ids = index.geo_faceted_documents_ids(rtxn)?;
return Ok(geo_faceted_doc_ids - result); Ok(geo_faceted_doc_ids - result)
} }
} }
} }