Prepare refactor of facets database

Prepare refactor of facets database
This commit is contained in:
Loïc Lecrenier
2022-08-29 16:01:54 +02:00
committed by Loïc Lecrenier
parent 004c09a8e2
commit c3f49f766d
27 changed files with 1662 additions and 1624 deletions

View File

@ -6,10 +6,7 @@ use heed::types::ByteSlice;
use heed::BytesDecode;
use roaring::RoaringBitmap;
use crate::heed_codec::facet::{
FacetLevelValueU32Codec, FacetStringLevelZeroCodec, FacetStringLevelZeroValueCodec,
FacetStringZeroBoundsValueCodec,
};
use crate::heed_codec::facet::FacetStringZeroBoundsValueCodec;
use crate::{make_db_snap_from_iter, CboRoaringBitmapCodec, ExternalDocumentsIds, Index};
#[track_caller]
@ -232,46 +229,48 @@ pub fn snap_word_prefix_position_docids(index: &Index) -> String {
snap
}
pub fn snap_facet_id_f64_docids(index: &Index) -> String {
let snap = make_db_snap_from_iter!(index, facet_id_f64_docids, |(
(facet_id, level, left, right),
b,
)| {
&format!("{facet_id:<3} {level:<2} {left:<6} {right:<6} {}", display_bitmap(&b))
});
snap
todo!()
// let snap = make_db_snap_from_iter!(index, facet_id_f64_docids, |(
// (facet_id, level, left, right),
// b,
// )| {
// &format!("{facet_id:<3} {level:<2} {left:<6} {right:<6} {}", display_bitmap(&b))
// });
// snap
}
pub fn snap_facet_id_string_docids(index: &Index) -> String {
let rtxn = index.read_txn().unwrap();
let bytes_db = index.facet_id_string_docids.remap_types::<ByteSlice, ByteSlice>();
let iter = bytes_db.iter(&rtxn).unwrap();
let mut snap = String::new();
todo!()
// let rtxn = index.read_txn().unwrap();
// let bytes_db = index.facet_id_string_docids.remap_types::<ByteSlice, ByteSlice>();
// let iter = bytes_db.iter(&rtxn).unwrap();
// let mut snap = String::new();
for x in iter {
let (key, value) = x.unwrap();
if let Some((field_id, normalized_str)) = FacetStringLevelZeroCodec::bytes_decode(key) {
let (orig_string, docids) =
FacetStringLevelZeroValueCodec::bytes_decode(value).unwrap();
snap.push_str(&format!(
"{field_id:<3} {normalized_str:<8} {orig_string:<8} {}\n",
display_bitmap(&docids)
));
} else if let Some((field_id, level, left, right)) =
FacetLevelValueU32Codec::bytes_decode(key)
{
snap.push_str(&format!("{field_id:<3} {level:<2} {left:<6} {right:<6} "));
let (bounds, docids) =
FacetStringZeroBoundsValueCodec::<CboRoaringBitmapCodec>::bytes_decode(value)
.unwrap();
if let Some((left, right)) = bounds {
snap.push_str(&format!("{left:<8} {right:<8} "));
}
snap.push_str(&display_bitmap(&docids));
snap.push('\n');
} else {
panic!();
}
}
snap
// for x in iter {
// let (key, value) = x.unwrap();
// if let Some((field_id, normalized_str)) = FacetStringLevelZeroCodec::bytes_decode(key) {
// let (orig_string, docids) =
// FacetStringLevelZeroValueCodec::bytes_decode(value).unwrap();
// snap.push_str(&format!(
// "{field_id:<3} {normalized_str:<8} {orig_string:<8} {}\n",
// display_bitmap(&docids)
// ));
// } else if let Some((field_id, level, left, right)) =
// FacetLevelValueU32Codec::bytes_decode(key)
// {
// snap.push_str(&format!("{field_id:<3} {level:<2} {left:<6} {right:<6} "));
// let (bounds, docids) =
// FacetStringZeroBoundsValueCodec::<CboRoaringBitmapCodec>::bytes_decode(value)
// .unwrap();
// if let Some((left, right)) = bounds {
// snap.push_str(&format!("{left:<8} {right:<8} "));
// }
// snap.push_str(&display_bitmap(&docids));
// snap.push('\n');
// } else {
// panic!();
// }
// }
// snap
}
pub fn snap_documents_ids(index: &Index) -> String {
let rtxn = index.read_txn().unwrap();