From 042d86cbb3c5ea6251f24ec633d00ace32d12803 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 1 Feb 2023 14:40:42 +0100 Subject: [PATCH] facet sort ascending/descending now also return the values --- .../src/search/facet/facet_sort_ascending.rs | 19 ++++++++++--------- .../src/search/facet/facet_sort_descending.rs | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/milli/src/search/facet/facet_sort_ascending.rs b/milli/src/search/facet/facet_sort_ascending.rs index 32cf5c355..b0f1dccd5 100644 --- a/milli/src/search/facet/facet_sort_ascending.rs +++ b/milli/src/search/facet/facet_sort_ascending.rs @@ -34,7 +34,7 @@ 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 }; @@ -60,7 +60,7 @@ struct AscendingFacetSort<'t, 'e> { } impl<'t, 'e> Iterator for AscendingFacetSort<'t, 'e> { - type Item = Result; + type Item = Result<(RoaringBitmap, &'t [u8])>; fn next(&mut self) -> Option { 'outer: loop { @@ -90,7 +90,8 @@ impl<'t, 'e> Iterator for AscendingFacetSort<'t, 'e> { *documents_ids -= &bitmap; if level == 0 { - return Some(Ok(bitmap)); + // Since the level is 0, the left_bound is the exact value. + return Some(Ok((bitmap, left_bound))); } let starting_key_below = FacetGroupKey { field_id: self.field_id, level: level - 1, left_bound }; @@ -130,7 +131,7 @@ mod tests { let mut results = String::new(); let iter = ascending_facet_sort(&txn, index.content, 0, candidates).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } @@ -152,7 +153,7 @@ mod tests { let mut results = String::new(); let iter = ascending_facet_sort(&txn, index.content, 0, candidates.clone()).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } @@ -161,7 +162,7 @@ mod tests { let mut results = String::new(); let iter = ascending_facet_sort(&txn, index.content, 1, candidates).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } @@ -183,7 +184,7 @@ mod tests { let mut results = String::new(); let iter = ascending_facet_sort(&txn, index.content, 0, candidates.clone()).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } @@ -192,7 +193,7 @@ mod tests { let mut results = String::new(); let iter = ascending_facet_sort(&txn, index.content, 1, candidates).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } @@ -214,7 +215,7 @@ mod tests { let mut results = String::new(); let iter = ascending_facet_sort(&txn, index.content, 3, candidates.clone()).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } diff --git a/milli/src/search/facet/facet_sort_descending.rs b/milli/src/search/facet/facet_sort_descending.rs index 4d1fdd1e7..fbcc41b9d 100644 --- a/milli/src/search/facet/facet_sort_descending.rs +++ b/milli/src/search/facet/facet_sort_descending.rs @@ -17,7 +17,7 @@ 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 }; @@ -50,7 +50,7 @@ struct DescendingFacetSort<'t> { } impl<'t> Iterator for DescendingFacetSort<'t> { - type Item = Result; + type Item = Result<(RoaringBitmap, &'t [u8])>; fn next(&mut self) -> Option { 'outer: loop { @@ -77,7 +77,8 @@ impl<'t> Iterator for DescendingFacetSort<'t> { *documents_ids -= &bitmap; if level == 0 { - return Some(Ok(bitmap)); + // Since we're at the level 0 the left_bound is the exact value. + return Some(Ok((bitmap, left_bound))); } let starting_key_below = FacetGroupKey { field_id, level: level - 1, left_bound }; @@ -146,7 +147,7 @@ mod tests { let db = index.content.remap_key_type::>(); let iter = descending_facet_sort(&txn, db, 0, candidates).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } @@ -169,7 +170,7 @@ mod tests { let db = index.content.remap_key_type::>(); let iter = descending_facet_sort(&txn, db, 0, candidates.clone()).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } @@ -179,7 +180,7 @@ mod tests { let iter = descending_facet_sort(&txn, db, 1, candidates).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } @@ -200,7 +201,7 @@ mod tests { let mut results = String::new(); let iter = descending_facet_sort(&txn, index.content, 0, candidates.clone()).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } @@ -209,7 +210,7 @@ mod tests { let mut results = String::new(); let iter = descending_facet_sort(&txn, index.content, 1, candidates).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); } @@ -231,7 +232,7 @@ mod tests { let mut results = String::new(); let iter = descending_facet_sort(&txn, index.content, 3, candidates.clone()).unwrap(); for el in iter { - let docids = el.unwrap(); + let (docids, _) = el.unwrap(); results.push_str(&display_bitmap(&docids)); results.push('\n'); }