From 70e9b1e9363f618fb898efa3df1f8c304b14073d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 20 Jan 2021 17:11:36 +0100 Subject: [PATCH] Introduce a flag to the search subcommand to display the facet distribution --- src/subcommand/search.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/subcommand/search.rs b/src/subcommand/search.rs index d816c47fe..178ef9941 100644 --- a/src/subcommand/search.rs +++ b/src/subcommand/search.rs @@ -29,6 +29,10 @@ pub struct Opt { /// The query string to search for (doesn't support prefix search yet). query: Option, + + /// Compute and print the facet distribution of all the faceted fields. + #[structopt(long)] + print_facet_distribution: bool, } pub fn run(opt: Opt) -> anyhow::Result<()> { @@ -71,6 +75,12 @@ pub fn run(opt: Opt) -> anyhow::Result<()> { 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()); }