Optimize geo sort

This commit is contained in:
Mubelotix 2025-07-01 11:50:01 +02:00
parent 8326f34ad1
commit 8aacd6374a
No known key found for this signature in database
GPG key ID: 0406DF6C3A69B942

View file

@ -370,7 +370,7 @@ pub fn recursive_facet_sort<'ctx>(
let mut fields = Vec::new();
let fields_ids_map = index.fields_ids_map(rtxn)?;
let geo_candidates = index.geo_faceted_documents_ids(rtxn)?; // TODO: skip when no geo sort
let mut need_geo_candidates = false;
for sort in sort {
match sort {
AscDesc::Asc(Member::Field(field)) => {
@ -387,6 +387,7 @@ pub fn recursive_facet_sort<'ctx>(
if let (Some(lat), Some(lng)) =
(fields_ids_map.id("_geo.lat"), fields_ids_map.id("_geo.lng"))
{
need_geo_candidates = true;
fields.push(AscDescId::Geo {
field_ids: [lat, lng],
target_point,
@ -398,6 +399,7 @@ pub fn recursive_facet_sort<'ctx>(
if let (Some(lat), Some(lng)) =
(fields_ids_map.id("_geo.lat"), fields_ids_map.id("_geo.lng"))
{
need_geo_candidates = true;
fields.push(AscDescId::Geo {
field_ids: [lat, lng],
target_point,
@ -409,6 +411,12 @@ pub fn recursive_facet_sort<'ctx>(
// FIXME: Should this return an error if the field is not found?
}
let geo_candidates = if need_geo_candidates {
index.geo_faceted_documents_ids(rtxn)?
} else {
RoaringBitmap::new()
};
let number_db = index.facet_id_f64_docids.remap_key_type::<FacetGroupKeyCodec<BytesRefCodec>>();
let string_db =
index.facet_id_string_docids.remap_key_type::<FacetGroupKeyCodec<BytesRefCodec>>();