Rework the FacetDistribution execute method to use the faceted_fields struct

This commit is contained in:
Clément Renault 2021-01-27 14:53:50 +01:00
parent 9c8a654079
commit 11309ee99c
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -196,22 +196,20 @@ impl<'a> FacetDistribution<'a> {
pub fn execute(&self) -> heed::Result<BTreeMap<String, BTreeMap<FacetValue, u64>>> { pub fn execute(&self) -> heed::Result<BTreeMap<String, BTreeMap<FacetValue, u64>>> {
let fields_ids_map = self.index.fields_ids_map(self.rtxn)?; 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 { let fields_ids: Vec<_> = match &self.facets {
Some(names) => { Some(names) => names
names.iter().filter_map(|n| { .iter()
let id = fields_ids_map.id(n)?; .filter_map(|n| faceted_fields.get(n).map(|t| (n.to_string(), *t)))
faceted_fields.get(&id).cloned().map(|t| (id, t)) .collect(),
}).collect() None => faceted_fields.into_iter().collect(),
},
None => faceted_fields.iter().map(|(id, t)| (*id, *t)).collect(),
}; };
let mut facets_values = BTreeMap::new(); let mut facets_values = BTreeMap::new();
for (fid, ftype) in fields_ids { for (name, ftype) in fields_ids {
let facet_name = fields_ids_map.name(fid).unwrap(); let fid = fields_ids_map.id(&name).unwrap();
let values = self.facet_values(fid, ftype)?; let values = self.facet_values(fid, ftype)?;
facets_values.insert(facet_name.to_string(), values); facets_values.insert(name, values);
} }
Ok(facets_values) Ok(facets_values)