if we have no rtree we return all other provided documents

This commit is contained in:
Tamo 2021-09-09 15:19:47 +02:00
parent a84f3a8b31
commit 3fc145c254
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69
3 changed files with 11 additions and 10 deletions

View File

@ -142,8 +142,9 @@ where
Some((head, tail))
}
/// Return the distance between two points in meters.
fn distance_between_two_points(a: &[f64; 2], b: &[f64; 2]) -> f64 {
/// Return the distance between two points in meters. Each points are composed of two f64,
/// one latitude and one longitude.
pub fn distance_between_two_points(a: &[f64; 2], b: &[f64; 2]) -> f64 {
let a = haversine::Location { latitude: a[0], longitude: a[1] };
let b = haversine::Location { latitude: b[0], longitude: b[1] };

View File

@ -45,11 +45,7 @@ impl<'t> Geo<'t> {
impl Criterion for Geo<'_> {
fn next(&mut self, params: &mut CriterionParameters) -> Result<Option<CriterionResult>> {
// if there is no rtree we have nothing to returns
let rtree = match self.rtree.as_ref() {
Some(rtree) => rtree,
None => return Ok(None),
};
let rtree = self.rtree.as_ref();
loop {
match self.candidates.next() {
@ -92,8 +88,12 @@ impl Criterion for Geo<'_> {
continue;
}
self.allowed_candidates = &candidates - params.excluded_candidates;
self.candidates =
geo_point(rtree, self.allowed_candidates.clone(), self.point);
self.candidates = match rtree {
Some(rtree) => {
geo_point(rtree, self.allowed_candidates.clone(), self.point)
}
None => Box::new(std::iter::empty()),
};
}
None => return Ok(None),
},

View File

@ -312,7 +312,7 @@ impl<'t> CriteriaBuilder<'t> {
)?),
AscDescName::Desc(Member::Geo(_point)) => {
return Err(UserError::InvalidSortName {
name: "Sorting in descending order is currently not supported for the geosearch".to_string(),
name: "sorting in descending order is not supported for the geosearch".to_string(),
})?
}
};