mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
geosort: Remove rtree unwrap
This commit is contained in:
parent
c85392ce40
commit
342c4ff85d
@ -109,16 +109,23 @@ impl<Q: RankingRuleQueryTrait> GeoSort<Q> {
|
|||||||
debug_assert!(self.field_ids.is_some(), "fill_buffer can't be called without the lat&lng");
|
debug_assert!(self.field_ids.is_some(), "fill_buffer can't be called without the lat&lng");
|
||||||
debug_assert!(self.cached_sorted_docids.is_empty());
|
debug_assert!(self.cached_sorted_docids.is_empty());
|
||||||
|
|
||||||
// if we had an rtree and the strategy doesn't require one anymore we can drop it
|
// lazily initialize the rtree if needed by the strategy, and cache it in `self.rtree`
|
||||||
let use_rtree = self.strategy.use_rtree(self.geo_candidates.len() as usize);
|
let rtree = if self.strategy.use_rtree(self.geo_candidates.len() as usize) {
|
||||||
if use_rtree && self.rtree.is_none() {
|
if let Some(rtree) = self.rtree.as_ref() {
|
||||||
self.rtree = Some(ctx.index.geo_rtree(ctx.txn)?.expect("geo candidates but no rtree"));
|
// get rtree from cache
|
||||||
}
|
Some(rtree)
|
||||||
|
} else {
|
||||||
|
let rtree = ctx.index.geo_rtree(ctx.txn)?.expect("geo candidates but no rtree");
|
||||||
|
// insert rtree in cache and returns it.
|
||||||
|
// Can't use `get_or_insert_with` because getting the rtree from the DB is a fallible operation.
|
||||||
|
Some(&*self.rtree.insert(rtree))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let cache_size = self.strategy.cache_size();
|
let cache_size = self.strategy.cache_size();
|
||||||
if use_rtree {
|
if let Some(rtree) = rtree {
|
||||||
let rtree = self.rtree.as_ref().unwrap();
|
|
||||||
|
|
||||||
if self.ascending {
|
if self.ascending {
|
||||||
let point = lat_lng_to_xyz(&self.point);
|
let point = lat_lng_to_xyz(&self.point);
|
||||||
for point in rtree.nearest_neighbor_iter(&point) {
|
for point in rtree.nearest_neighbor_iter(&point) {
|
||||||
|
Loading…
Reference in New Issue
Block a user