mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 09:04:59 +08:00
use meters in the filters
This commit is contained in:
parent
4f69b190bc
commit
e5ef0cad9a
@ -16,6 +16,7 @@ flate2 = "1.0.20"
|
||||
fst = "0.4.5"
|
||||
fxhash = "0.2.1"
|
||||
grenad = { version = "0.3.1", default-features = false, features = ["tempfile"] }
|
||||
haversine = "0.2.1"
|
||||
heed = { git = "https://github.com/Kerollmops/heed", tag = "v0.12.1", default-features = false, features = ["lmdb", "sync-read-txn"] }
|
||||
human_format = "1.0.3"
|
||||
levenshtein_automata = { version = "0.2.0", features = ["fst_automaton"] }
|
||||
|
@ -142,6 +142,14 @@ where
|
||||
Some((head, tail))
|
||||
}
|
||||
|
||||
/// Return the distance between two points in meters
|
||||
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] };
|
||||
|
||||
haversine::distance(a, b, haversine::Units::Kilometers) * 1000.
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
@ -504,17 +504,20 @@ impl FilterCondition {
|
||||
LowerThan(val) => (Included(f64::MIN), Excluded(*val)),
|
||||
LowerThanOrEqual(val) => (Included(f64::MIN), Included(*val)),
|
||||
Between(left, right) => (Included(*left), Included(*right)),
|
||||
GeoLowerThan(point, distance) => {
|
||||
GeoLowerThan(base_point, distance) => {
|
||||
let mut result = RoaringBitmap::new();
|
||||
let rtree = match index.geo_rtree(rtxn)? {
|
||||
Some(rtree) => rtree,
|
||||
None => return Ok(result),
|
||||
};
|
||||
|
||||
let iter = rtree
|
||||
.nearest_neighbor_iter_with_distance_2(point)
|
||||
.take_while(|(_, dist)| dist <= distance);
|
||||
iter.for_each(|(point, _)| drop(result.insert(point.data)));
|
||||
rtree
|
||||
.nearest_neighbor_iter(base_point)
|
||||
.take_while(|point| {
|
||||
dbg!(crate::distance_between_two_points(base_point, point.geom()))
|
||||
< *distance
|
||||
})
|
||||
.for_each(|point| drop(result.insert(point.data)));
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user