From 11309ee99c6ad8d6d708a076847db6dfff615eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 27 Jan 2021 14:53:50 +0100 Subject: [PATCH] Rework the FacetDistribution execute method to use the faceted_fields struct --- src/search/facet/facet_distribution.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/search/facet/facet_distribution.rs b/src/search/facet/facet_distribution.rs index 10fe1a3c3..01f7b7205 100644 --- a/src/search/facet/facet_distribution.rs +++ b/src/search/facet/facet_distribution.rs @@ -196,22 +196,20 @@ impl<'a> FacetDistribution<'a> { pub fn execute(&self) -> heed::Result>> { let fields_ids_map = self.index.fields_ids_map(self.rtxn)?; - let faceted_fields = self.index.faceted_fields_ids(self.rtxn)?; + let faceted_fields = self.index.faceted_fields(self.rtxn)?; let fields_ids: Vec<_> = match &self.facets { - Some(names) => { - names.iter().filter_map(|n| { - let id = fields_ids_map.id(n)?; - faceted_fields.get(&id).cloned().map(|t| (id, t)) - }).collect() - }, - None => faceted_fields.iter().map(|(id, t)| (*id, *t)).collect(), + Some(names) => names + .iter() + .filter_map(|n| faceted_fields.get(n).map(|t| (n.to_string(), *t))) + .collect(), + None => faceted_fields.into_iter().collect(), }; let mut facets_values = BTreeMap::new(); - for (fid, ftype) in fields_ids { - let facet_name = fields_ids_map.name(fid).unwrap(); + for (name, ftype) in fields_ids { + let fid = fields_ids_map.id(&name).unwrap(); let values = self.facet_values(fid, ftype)?; - facets_values.insert(facet_name.to_string(), values); + facets_values.insert(name, values); } Ok(facets_values)