From b52d500fbca32847ebefb557623c611caac9d1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 27 Jan 2021 14:36:49 +0100 Subject: [PATCH] Reorder the FacetType enum branching in the facet_value method --- src/search/facet/facet_distribution.rs | 50 +++++++++++++------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/search/facet/facet_distribution.rs b/src/search/facet/facet_distribution.rs index 8bab2cb62..490a18229 100644 --- a/src/search/facet/facet_distribution.rs +++ b/src/search/facet/facet_distribution.rs @@ -66,6 +66,21 @@ impl<'a> FacetDistribution<'a> { if candidates.len() <= CANDIDATES_THRESHOLD { let mut key_buffer = vec![field_id]; 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::(); + for result in iter { + let ((_, _, value), ()) = result?; + *facet_values.entry(FacetValue::from(value)).or_insert(0) += 1; + } + } + Ok(facet_values) + }, FacetType::Float => { let mut facet_values = BTreeMap::new(); for docid in candidates { @@ -96,21 +111,6 @@ impl<'a> FacetDistribution<'a> { } 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::(); - for result in iter { - let ((_, _, value), ()) = result?; - *facet_values.entry(FacetValue::from(value)).or_insert(0) += 1; - } - } - Ok(facet_values) - }, } } else { let iter = match facet_type { @@ -122,14 +122,14 @@ impl<'a> FacetDistribution<'a> { .map(|r| r.map(|((_, v), docids)| (FacetValue::from(v), docids))); Box::new(iter) as Box::> }, - FacetType::Integer => { - let iter = FacetIter::::new_non_reducing( + FacetType::Float => { + let iter = FacetIter::::new_non_reducing( self.rtxn, self.index, field_id, candidates.clone(), )?; Box::new(iter.map(|r| r.map(|(v, docids)| (FacetValue::from(v), docids)))) }, - FacetType::Float => { - let iter = FacetIter::::new_non_reducing( + FacetType::Integer => { + let iter = FacetIter::::new_non_reducing( self.rtxn, self.index, field_id, candidates.clone(), )?; 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))); Box::new(iter) as Box::> }, - FacetType::Integer => { - let db = db.remap_key_type::(); - let range = FacetRange::::new( + FacetType::Float => { + let db = db.remap_key_type::(); + let range = FacetRange::::new( self.rtxn, db, field_id, 0, Unbounded, Unbounded, )?; Box::new(range.map(|r| r.map(|((_, _, v, _), docids)| (FacetValue::from(v), docids)))) }, - FacetType::Float => { - let db = db.remap_key_type::(); - let range = FacetRange::::new( + FacetType::Integer => { + let db = db.remap_key_type::(); + let range = FacetRange::::new( self.rtxn, db, field_id, 0, Unbounded, Unbounded, )?; Box::new(range.map(|r| r.map(|((_, _, v, _), docids)| (FacetValue::from(v), docids))))