mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-12 06:24:29 +01:00
Reorder the FacetType enum branching in the facet_value method
This commit is contained in:
parent
d91d321129
commit
b52d500fbc
@ -66,6 +66,21 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
if candidates.len() <= CANDIDATES_THRESHOLD {
|
if candidates.len() <= CANDIDATES_THRESHOLD {
|
||||||
let mut key_buffer = vec![field_id];
|
let mut key_buffer = vec![field_id];
|
||||||
match facet_type {
|
match facet_type {
|
||||||
|
FacetType::String => {
|
||||||
|
let mut facet_values = BTreeMap::new();
|
||||||
|
for docid in candidates {
|
||||||
|
key_buffer.truncate(1);
|
||||||
|
key_buffer.extend_from_slice(&docid.to_be_bytes());
|
||||||
|
let iter = self.index.field_id_docid_facet_values
|
||||||
|
.prefix_iter(self.rtxn, &key_buffer)?
|
||||||
|
.remap_key_type::<FieldDocIdFacetStringCodec>();
|
||||||
|
for result in iter {
|
||||||
|
let ((_, _, value), ()) = result?;
|
||||||
|
*facet_values.entry(FacetValue::from(value)).or_insert(0) += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(facet_values)
|
||||||
|
},
|
||||||
FacetType::Float => {
|
FacetType::Float => {
|
||||||
let mut facet_values = BTreeMap::new();
|
let mut facet_values = BTreeMap::new();
|
||||||
for docid in candidates {
|
for docid in candidates {
|
||||||
@ -96,21 +111,6 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
}
|
}
|
||||||
Ok(facet_values)
|
Ok(facet_values)
|
||||||
},
|
},
|
||||||
FacetType::String => {
|
|
||||||
let mut facet_values = BTreeMap::new();
|
|
||||||
for docid in candidates {
|
|
||||||
key_buffer.truncate(1);
|
|
||||||
key_buffer.extend_from_slice(&docid.to_be_bytes());
|
|
||||||
let iter = self.index.field_id_docid_facet_values
|
|
||||||
.prefix_iter(self.rtxn, &key_buffer)?
|
|
||||||
.remap_key_type::<FieldDocIdFacetStringCodec>();
|
|
||||||
for result in iter {
|
|
||||||
let ((_, _, value), ()) = result?;
|
|
||||||
*facet_values.entry(FacetValue::from(value)).or_insert(0) += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(facet_values)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let iter = match facet_type {
|
let iter = match facet_type {
|
||||||
@ -122,14 +122,14 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
.map(|r| r.map(|((_, v), docids)| (FacetValue::from(v), docids)));
|
.map(|r| r.map(|((_, v), docids)| (FacetValue::from(v), docids)));
|
||||||
Box::new(iter) as Box::<dyn Iterator<Item=_>>
|
Box::new(iter) as Box::<dyn Iterator<Item=_>>
|
||||||
},
|
},
|
||||||
FacetType::Integer => {
|
FacetType::Float => {
|
||||||
let iter = FacetIter::<i64, FacetLevelValueI64Codec>::new_non_reducing(
|
let iter = FacetIter::<f64, FacetLevelValueF64Codec>::new_non_reducing(
|
||||||
self.rtxn, self.index, field_id, candidates.clone(),
|
self.rtxn, self.index, field_id, candidates.clone(),
|
||||||
)?;
|
)?;
|
||||||
Box::new(iter.map(|r| r.map(|(v, docids)| (FacetValue::from(v), docids))))
|
Box::new(iter.map(|r| r.map(|(v, docids)| (FacetValue::from(v), docids))))
|
||||||
},
|
},
|
||||||
FacetType::Float => {
|
FacetType::Integer => {
|
||||||
let iter = FacetIter::<f64, FacetLevelValueF64Codec>::new_non_reducing(
|
let iter = FacetIter::<i64, FacetLevelValueI64Codec>::new_non_reducing(
|
||||||
self.rtxn, self.index, field_id, candidates.clone(),
|
self.rtxn, self.index, field_id, candidates.clone(),
|
||||||
)?;
|
)?;
|
||||||
Box::new(iter.map(|r| r.map(|(v, docids)| (FacetValue::from(v), docids))))
|
Box::new(iter.map(|r| r.map(|(v, docids)| (FacetValue::from(v), docids))))
|
||||||
@ -160,16 +160,16 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
.map(|r| r.map(|((_, v), docids)| (FacetValue::from(v), docids)));
|
.map(|r| r.map(|((_, v), docids)| (FacetValue::from(v), docids)));
|
||||||
Box::new(iter) as Box::<dyn Iterator<Item=_>>
|
Box::new(iter) as Box::<dyn Iterator<Item=_>>
|
||||||
},
|
},
|
||||||
FacetType::Integer => {
|
FacetType::Float => {
|
||||||
let db = db.remap_key_type::<FacetLevelValueI64Codec>();
|
let db = db.remap_key_type::<FacetLevelValueF64Codec>();
|
||||||
let range = FacetRange::<i64, _>::new(
|
let range = FacetRange::<f64, _>::new(
|
||||||
self.rtxn, db, field_id, 0, Unbounded, Unbounded,
|
self.rtxn, db, field_id, 0, Unbounded, Unbounded,
|
||||||
)?;
|
)?;
|
||||||
Box::new(range.map(|r| r.map(|((_, _, v, _), docids)| (FacetValue::from(v), docids))))
|
Box::new(range.map(|r| r.map(|((_, _, v, _), docids)| (FacetValue::from(v), docids))))
|
||||||
},
|
},
|
||||||
FacetType::Float => {
|
FacetType::Integer => {
|
||||||
let db = db.remap_key_type::<FacetLevelValueF64Codec>();
|
let db = db.remap_key_type::<FacetLevelValueI64Codec>();
|
||||||
let range = FacetRange::<f64, _>::new(
|
let range = FacetRange::<i64, _>::new(
|
||||||
self.rtxn, db, field_id, 0, Unbounded, Unbounded,
|
self.rtxn, db, field_id, 0, Unbounded, Unbounded,
|
||||||
)?;
|
)?;
|
||||||
Box::new(range.map(|r| r.map(|((_, _, v, _), docids)| (FacetValue::from(v), docids))))
|
Box::new(range.map(|r| r.map(|((_, _, v, _), docids)| (FacetValue::from(v), docids))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user