mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 00:31:02 +00:00
Fix panic
This commit is contained in:
@ -128,37 +128,60 @@ impl<'ctx> SortedDocumentsIteratorBuilder<'ctx> {
|
|||||||
let mut cache = VecDeque::new();
|
let mut cache = VecDeque::new();
|
||||||
let mut rtree = None;
|
let mut rtree = None;
|
||||||
let size = candidates.len() as usize;
|
let size = candidates.len() as usize;
|
||||||
|
let not_geo_candidates = candidates.clone() - geo_candidates;
|
||||||
|
let mut geo_remaining = size - not_geo_candidates.len() as usize;
|
||||||
|
let mut not_geo_candidates = Some(not_geo_candidates);
|
||||||
|
|
||||||
let next_children = std::iter::from_fn(move || {
|
let next_children = std::iter::from_fn(move || {
|
||||||
match next_bucket(
|
// Find the next bucket of geo-sorted documents.
|
||||||
index,
|
// next_bucket loops and will go back to the beginning so we use a variable to track how many are left.
|
||||||
rtxn,
|
if geo_remaining > 0 {
|
||||||
&candidates,
|
if let Ok(Some((docids, _point))) = next_bucket(
|
||||||
ascending,
|
|
||||||
target_point,
|
|
||||||
&Some(field_ids),
|
|
||||||
&mut rtree,
|
|
||||||
&mut cache,
|
|
||||||
geo_candidates,
|
|
||||||
GeoSortParameter::default(),
|
|
||||||
) {
|
|
||||||
Ok(Some((docids, _point))) => Some(Ok(SortedDocumentsIteratorBuilder {
|
|
||||||
index,
|
index,
|
||||||
rtxn,
|
rtxn,
|
||||||
number_db,
|
&candidates,
|
||||||
string_db,
|
ascending,
|
||||||
fields: &fields[1..],
|
target_point,
|
||||||
candidates: docids,
|
&Some(field_ids),
|
||||||
|
&mut rtree,
|
||||||
|
&mut cache,
|
||||||
geo_candidates,
|
geo_candidates,
|
||||||
})),
|
GeoSortParameter::default(),
|
||||||
Ok(None) => None,
|
) {
|
||||||
Err(e) => Some(Err(e)),
|
geo_remaining -= docids.len() as usize;
|
||||||
|
return Some(Ok(SortedDocumentsIteratorBuilder {
|
||||||
|
index,
|
||||||
|
rtxn,
|
||||||
|
number_db,
|
||||||
|
string_db,
|
||||||
|
fields: &fields[1..],
|
||||||
|
candidates: docids,
|
||||||
|
geo_candidates,
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Once all geo candidates have been processed, we can return the others
|
||||||
|
if let Some(not_geo_candidates) = not_geo_candidates.take() {
|
||||||
|
if !not_geo_candidates.is_empty() {
|
||||||
|
return Some(Ok(SortedDocumentsIteratorBuilder {
|
||||||
|
index,
|
||||||
|
rtxn,
|
||||||
|
number_db,
|
||||||
|
string_db,
|
||||||
|
fields: &fields[1..],
|
||||||
|
candidates: not_geo_candidates,
|
||||||
|
geo_candidates,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(SortedDocumentsIterator::Branch {
|
Ok(SortedDocumentsIterator::Branch {
|
||||||
current_child: None,
|
current_child: None,
|
||||||
next_children_size: size, // TODO: confirm all candidates will be included
|
next_children_size: size,
|
||||||
next_children: Box::new(next_children),
|
next_children: Box::new(next_children),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user