mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-12-02 01:55:03 +08:00
Rework the FacetDistribution execute method to use the faceted_fields struct
This commit is contained in:
parent
9c8a654079
commit
11309ee99c
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user