From 0a1beb688c0f21a53c317f762c80a8b46299aee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sun, 3 Jan 2021 12:49:09 +0100 Subject: [PATCH] Improve the facet value displaying, extracting the facet level --- src/subcommand/infos.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/subcommand/infos.rs b/src/subcommand/infos.rs index 81c2a2fed..fc645899a 100644 --- a/src/subcommand/infos.rs +++ b/src/subcommand/infos.rs @@ -1,3 +1,4 @@ +use std::fmt::Write as _; use std::path::PathBuf; use std::{str, io, fmt}; @@ -278,11 +279,11 @@ where } } -fn facet_number_value_to_string(level: u8, left: T, right: T) -> String { +fn facet_number_value_to_string(level: u8, left: T, right: T) -> (u8, String) { if level == 0 { - format!("{:?} (level {})", left, level) + (level, format!("{:?}", left)) } else { - format!("{:?} to {:?} (level {})", left, right, level) + (level, format!("{:?} to {:?}", left, right)) } } @@ -353,8 +354,16 @@ fn biggest_value_sizes(index: &Index, rtxn: &heed::RoTxn, limit: usize) -> anyho field_id, field_type, |key| key.to_owned(), - facet_number_value_to_string, - facet_number_value_to_string, + |level, left, right| { + let mut output = facet_number_value_to_string(level, left, right).1; + let _ = write!(&mut output, " (level {})", level); + output + }, + |level, left, right| { + let mut output = facet_number_value_to_string(level, left, right).1; + let _ = write!(&mut output, " (level {})", level); + output + }, )?; for result in iter { @@ -413,7 +422,7 @@ fn facet_values_docids(index: &Index, rtxn: &heed::RoTxn, debug: bool, field_nam let stdout = io::stdout(); let mut wtr = csv::Writer::from_writer(stdout.lock()); - wtr.write_record(&["facet_value", "documents_count", "documents_ids"])?; + wtr.write_record(&["facet_value", "facet_level", "documents_count", "documents_ids"])?; let db = index.facet_field_id_value_docids; let iter = facet_values_iter( @@ -421,20 +430,20 @@ fn facet_values_docids(index: &Index, rtxn: &heed::RoTxn, debug: bool, field_nam db, field_id, *field_type, - |key| key.to_owned(), + |key| (0, key.to_owned()), facet_number_value_to_string, facet_number_value_to_string, )?; for result in iter { - let (value, docids) = result?; + let ((level, value), docids) = result?; let count = docids.len(); let docids = if debug { format!("{:?}", docids) } else { format!("{:?}", docids.iter().collect::>()) }; - wtr.write_record(&[value, count.to_string(), docids])?; + wtr.write_record(&[value, level.to_string(), count.to_string(), docids])?; } Ok(wtr.flush()?)