From 3fc145c25447f44c4638c127937594bf0f406922 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 9 Sep 2021 15:19:47 +0200 Subject: [PATCH] if we have no rtree we return all other provided documents --- milli/src/lib.rs | 5 +++-- milli/src/search/criteria/geo.rs | 14 +++++++------- milli/src/search/criteria/mod.rs | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/milli/src/lib.rs b/milli/src/lib.rs index 4f066365c..fc27b9d72 100644 --- a/milli/src/lib.rs +++ b/milli/src/lib.rs @@ -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] }; diff --git a/milli/src/search/criteria/geo.rs b/milli/src/search/criteria/geo.rs index 78f741b57..c9dff307b 100644 --- a/milli/src/search/criteria/geo.rs +++ b/milli/src/search/criteria/geo.rs @@ -45,11 +45,7 @@ impl<'t> Geo<'t> { impl Criterion for Geo<'_> { fn next(&mut self, params: &mut CriterionParameters) -> Result> { - // 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), }, diff --git a/milli/src/search/criteria/mod.rs b/milli/src/search/criteria/mod.rs index 105a69194..3c9485012 100644 --- a/milli/src/search/criteria/mod.rs +++ b/milli/src/search/criteria/mod.rs @@ -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(), })? } };