Introduce a flag to the search subcommand to display the facet distribution

This commit is contained in:
Clément Renault 2021-01-20 17:11:36 +01:00 committed by Kerollmops
parent 61dbcfa44a
commit 70e9b1e936
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -29,6 +29,10 @@ pub struct Opt {
/// The query string to search for (doesn't support prefix search yet). /// The query string to search for (doesn't support prefix search yet).
query: Option<String>, query: Option<String>,
/// Compute and print the facet distribution of all the faceted fields.
#[structopt(long)]
print_facet_distribution: bool,
} }
pub fn run(opt: Opt) -> anyhow::Result<()> { pub fn run(opt: Opt) -> anyhow::Result<()> {
@ -71,6 +75,12 @@ pub fn run(opt: Opt) -> anyhow::Result<()> {
let _ = writeln!(&mut stdout); let _ = writeln!(&mut stdout);
} }
if opt.print_facet_distribution {
let facets = index.facets(&rtxn).candidates(result.candidates).execute()?;
serde_json::to_writer(&mut stdout, &facets)?;
let _ = writeln!(&mut stdout);
}
debug!("Took {:.02?} to find {} documents", before.elapsed(), result.documents_ids.len()); debug!("Took {:.02?} to find {} documents", before.elapsed(), result.documents_ids.len());
} }