From 9ac981d0255838ec9b2eefc2fb3453be3843ae77 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 1 Feb 2023 14:19:38 +0100 Subject: [PATCH] Remove some clippy type complexity warns by deboxing iters --- milli/src/search/criteria/asc_desc.rs | 29 ++++++++++--------- .../src/search/facet/facet_sort_ascending.rs | 11 +++++-- .../src/search/facet/facet_sort_descending.rs | 6 ++-- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/milli/src/search/criteria/asc_desc.rs b/milli/src/search/criteria/asc_desc.rs index a492096d7..378e1c8da 100644 --- a/milli/src/search/criteria/asc_desc.rs +++ b/milli/src/search/criteria/asc_desc.rs @@ -198,7 +198,7 @@ fn facet_ordered_iterative<'t>( } fn facet_extreme_value<'t>( - mut extreme_it: Box> + 't>, + mut extreme_it: impl Iterator> + 't, ) -> Result> { let extreme_value = if let Some(extreme_value) = extreme_it.next() { extreme_value } else { return Ok(None) }; @@ -236,21 +236,22 @@ fn facet_ordered_set_based<'t>( is_ascending: bool, candidates: RoaringBitmap, ) -> Result> + 't>> { - let make_iter = if is_ascending { ascending_facet_sort } else { descending_facet_sort }; + let number_db = + index.facet_id_f64_docids.remap_key_type::>(); + let string_db = + index.facet_id_string_docids.remap_key_type::>(); - let number_iter = make_iter( - rtxn, - index.facet_id_f64_docids.remap_key_type::>(), - field_id, - candidates.clone(), - )?; + let (number_iter, string_iter) = if is_ascending { + let number_iter = ascending_facet_sort(rtxn, number_db, field_id, candidates.clone())?; + let string_iter = ascending_facet_sort(rtxn, string_db, field_id, candidates)?; - let string_iter = make_iter( - rtxn, - index.facet_id_string_docids.remap_key_type::>(), - field_id, - candidates, - )?; + (itertools::Either::Left(number_iter), itertools::Either::Left(string_iter)) + } else { + let number_iter = descending_facet_sort(rtxn, number_db, field_id, candidates.clone())?; + let string_iter = descending_facet_sort(rtxn, string_db, field_id, candidates)?; + + (itertools::Either::Right(number_iter), itertools::Either::Right(string_iter)) + }; Ok(Box::new(number_iter.chain(string_iter).map(|res| res.map(|(doc_ids, _)| doc_ids)))) } diff --git a/milli/src/search/facet/facet_sort_ascending.rs b/milli/src/search/facet/facet_sort_ascending.rs index b0f1dccd5..f59b884de 100644 --- a/milli/src/search/facet/facet_sort_ascending.rs +++ b/milli/src/search/facet/facet_sort_ascending.rs @@ -34,15 +34,20 @@ pub fn ascending_facet_sort<'t>( db: heed::Database, FacetGroupValueCodec>, field_id: u16, candidates: RoaringBitmap, -) -> Result> + 't>> { +) -> Result> + 't> { let highest_level = get_highest_level(rtxn, db, field_id)?; if let Some(first_bound) = get_first_facet_value::(rtxn, db, field_id)? { let first_key = FacetGroupKey { field_id, level: highest_level, left_bound: first_bound }; let iter = db.range(rtxn, &(first_key..)).unwrap().take(usize::MAX); - Ok(Box::new(AscendingFacetSort { rtxn, db, field_id, stack: vec![(candidates, iter)] })) + Ok(itertools::Either::Left(AscendingFacetSort { + rtxn, + db, + field_id, + stack: vec![(candidates, iter)], + })) } else { - Ok(Box::new(std::iter::empty())) + Ok(itertools::Either::Right(std::iter::empty())) } } diff --git a/milli/src/search/facet/facet_sort_descending.rs b/milli/src/search/facet/facet_sort_descending.rs index fbcc41b9d..454b12859 100644 --- a/milli/src/search/facet/facet_sort_descending.rs +++ b/milli/src/search/facet/facet_sort_descending.rs @@ -17,21 +17,21 @@ pub fn descending_facet_sort<'t>( db: heed::Database, FacetGroupValueCodec>, field_id: u16, candidates: RoaringBitmap, -) -> Result> + 't>> { +) -> Result> + 't> { let highest_level = get_highest_level(rtxn, db, field_id)?; if let Some(first_bound) = get_first_facet_value::(rtxn, db, field_id)? { let first_key = FacetGroupKey { field_id, level: highest_level, left_bound: first_bound }; let last_bound = get_last_facet_value::(rtxn, db, field_id)?.unwrap(); let last_key = FacetGroupKey { field_id, level: highest_level, left_bound: last_bound }; let iter = db.rev_range(rtxn, &(first_key..=last_key))?.take(usize::MAX); - Ok(Box::new(DescendingFacetSort { + Ok(itertools::Either::Left(DescendingFacetSort { rtxn, db, field_id, stack: vec![(candidates, iter, Bound::Included(last_bound))], })) } else { - Ok(Box::new(std::iter::empty())) + Ok(itertools::Either::Right(std::iter::empty())) } }