mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-23 21:20:24 +01:00
facet sort ascending/descending now also return the values
This commit is contained in:
parent
c91bfeaf15
commit
042d86cbb3
@ -34,7 +34,7 @@ pub fn ascending_facet_sort<'t>(
|
|||||||
db: heed::Database<FacetGroupKeyCodec<ByteSliceRefCodec>, FacetGroupValueCodec>,
|
db: heed::Database<FacetGroupKeyCodec<ByteSliceRefCodec>, FacetGroupValueCodec>,
|
||||||
field_id: u16,
|
field_id: u16,
|
||||||
candidates: RoaringBitmap,
|
candidates: RoaringBitmap,
|
||||||
) -> Result<Box<dyn Iterator<Item = Result<RoaringBitmap>> + 't>> {
|
) -> Result<Box<dyn Iterator<Item = Result<(RoaringBitmap, &'t [u8])>> + 't>> {
|
||||||
let highest_level = get_highest_level(rtxn, db, field_id)?;
|
let highest_level = get_highest_level(rtxn, db, field_id)?;
|
||||||
if let Some(first_bound) = get_first_facet_value::<ByteSliceRefCodec>(rtxn, db, field_id)? {
|
if let Some(first_bound) = get_first_facet_value::<ByteSliceRefCodec>(rtxn, db, field_id)? {
|
||||||
let first_key = FacetGroupKey { field_id, level: highest_level, left_bound: first_bound };
|
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> {
|
impl<'t, 'e> Iterator for AscendingFacetSort<'t, 'e> {
|
||||||
type Item = Result<RoaringBitmap>;
|
type Item = Result<(RoaringBitmap, &'t [u8])>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
@ -90,7 +90,8 @@ impl<'t, 'e> Iterator for AscendingFacetSort<'t, 'e> {
|
|||||||
*documents_ids -= &bitmap;
|
*documents_ids -= &bitmap;
|
||||||
|
|
||||||
if level == 0 {
|
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 =
|
let starting_key_below =
|
||||||
FacetGroupKey { field_id: self.field_id, level: level - 1, left_bound };
|
FacetGroupKey { field_id: self.field_id, level: level - 1, left_bound };
|
||||||
@ -130,7 +131,7 @@ mod tests {
|
|||||||
let mut results = String::new();
|
let mut results = String::new();
|
||||||
let iter = ascending_facet_sort(&txn, index.content, 0, candidates).unwrap();
|
let iter = ascending_facet_sort(&txn, index.content, 0, candidates).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
@ -152,7 +153,7 @@ mod tests {
|
|||||||
let mut results = String::new();
|
let mut results = String::new();
|
||||||
let iter = ascending_facet_sort(&txn, index.content, 0, candidates.clone()).unwrap();
|
let iter = ascending_facet_sort(&txn, index.content, 0, candidates.clone()).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
@ -161,7 +162,7 @@ mod tests {
|
|||||||
let mut results = String::new();
|
let mut results = String::new();
|
||||||
let iter = ascending_facet_sort(&txn, index.content, 1, candidates).unwrap();
|
let iter = ascending_facet_sort(&txn, index.content, 1, candidates).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
@ -183,7 +184,7 @@ mod tests {
|
|||||||
let mut results = String::new();
|
let mut results = String::new();
|
||||||
let iter = ascending_facet_sort(&txn, index.content, 0, candidates.clone()).unwrap();
|
let iter = ascending_facet_sort(&txn, index.content, 0, candidates.clone()).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
@ -192,7 +193,7 @@ mod tests {
|
|||||||
let mut results = String::new();
|
let mut results = String::new();
|
||||||
let iter = ascending_facet_sort(&txn, index.content, 1, candidates).unwrap();
|
let iter = ascending_facet_sort(&txn, index.content, 1, candidates).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
@ -214,7 +215,7 @@ mod tests {
|
|||||||
let mut results = String::new();
|
let mut results = String::new();
|
||||||
let iter = ascending_facet_sort(&txn, index.content, 3, candidates.clone()).unwrap();
|
let iter = ascending_facet_sort(&txn, index.content, 3, candidates.clone()).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ pub fn descending_facet_sort<'t>(
|
|||||||
db: heed::Database<FacetGroupKeyCodec<ByteSliceRefCodec>, FacetGroupValueCodec>,
|
db: heed::Database<FacetGroupKeyCodec<ByteSliceRefCodec>, FacetGroupValueCodec>,
|
||||||
field_id: u16,
|
field_id: u16,
|
||||||
candidates: RoaringBitmap,
|
candidates: RoaringBitmap,
|
||||||
) -> Result<Box<dyn Iterator<Item = Result<RoaringBitmap>> + 't>> {
|
) -> Result<Box<dyn Iterator<Item = Result<(RoaringBitmap, &'t [u8])>> + 't>> {
|
||||||
let highest_level = get_highest_level(rtxn, db, field_id)?;
|
let highest_level = get_highest_level(rtxn, db, field_id)?;
|
||||||
if let Some(first_bound) = get_first_facet_value::<ByteSliceRefCodec>(rtxn, db, field_id)? {
|
if let Some(first_bound) = get_first_facet_value::<ByteSliceRefCodec>(rtxn, db, field_id)? {
|
||||||
let first_key = FacetGroupKey { field_id, level: highest_level, left_bound: first_bound };
|
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> {
|
impl<'t> Iterator for DescendingFacetSort<'t> {
|
||||||
type Item = Result<RoaringBitmap>;
|
type Item = Result<(RoaringBitmap, &'t [u8])>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
@ -77,7 +77,8 @@ impl<'t> Iterator for DescendingFacetSort<'t> {
|
|||||||
*documents_ids -= &bitmap;
|
*documents_ids -= &bitmap;
|
||||||
|
|
||||||
if level == 0 {
|
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 =
|
let starting_key_below =
|
||||||
FacetGroupKey { field_id, level: level - 1, left_bound };
|
FacetGroupKey { field_id, level: level - 1, left_bound };
|
||||||
@ -146,7 +147,7 @@ mod tests {
|
|||||||
let db = index.content.remap_key_type::<FacetGroupKeyCodec<ByteSliceRefCodec>>();
|
let db = index.content.remap_key_type::<FacetGroupKeyCodec<ByteSliceRefCodec>>();
|
||||||
let iter = descending_facet_sort(&txn, db, 0, candidates).unwrap();
|
let iter = descending_facet_sort(&txn, db, 0, candidates).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
@ -169,7 +170,7 @@ mod tests {
|
|||||||
let db = index.content.remap_key_type::<FacetGroupKeyCodec<ByteSliceRefCodec>>();
|
let db = index.content.remap_key_type::<FacetGroupKeyCodec<ByteSliceRefCodec>>();
|
||||||
let iter = descending_facet_sort(&txn, db, 0, candidates.clone()).unwrap();
|
let iter = descending_facet_sort(&txn, db, 0, candidates.clone()).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
@ -179,7 +180,7 @@ mod tests {
|
|||||||
|
|
||||||
let iter = descending_facet_sort(&txn, db, 1, candidates).unwrap();
|
let iter = descending_facet_sort(&txn, db, 1, candidates).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
@ -200,7 +201,7 @@ mod tests {
|
|||||||
let mut results = String::new();
|
let mut results = String::new();
|
||||||
let iter = descending_facet_sort(&txn, index.content, 0, candidates.clone()).unwrap();
|
let iter = descending_facet_sort(&txn, index.content, 0, candidates.clone()).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
@ -209,7 +210,7 @@ mod tests {
|
|||||||
let mut results = String::new();
|
let mut results = String::new();
|
||||||
let iter = descending_facet_sort(&txn, index.content, 1, candidates).unwrap();
|
let iter = descending_facet_sort(&txn, index.content, 1, candidates).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
@ -231,7 +232,7 @@ mod tests {
|
|||||||
let mut results = String::new();
|
let mut results = String::new();
|
||||||
let iter = descending_facet_sort(&txn, index.content, 3, candidates.clone()).unwrap();
|
let iter = descending_facet_sort(&txn, index.content, 3, candidates.clone()).unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let docids = el.unwrap();
|
let (docids, _) = el.unwrap();
|
||||||
results.push_str(&display_bitmap(&docids));
|
results.push_str(&display_bitmap(&docids));
|
||||||
results.push('\n');
|
results.push('\n');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user