diff --git a/meilidb-core/src/criterion/document_id.rs b/meilidb-core/src/criterion/document_id.rs index 27025a2da..34d0bd7f5 100644 --- a/meilidb-core/src/criterion/document_id.rs +++ b/meilidb-core/src/criterion/document_id.rs @@ -9,4 +9,8 @@ impl Criterion for DocumentId { fn evaluate(&self, lhs: &RawDocument, rhs: &RawDocument) -> Ordering { lhs.id.cmp(&rhs.id) } + + fn name(&self) -> &'static str { + "DocumentId" + } } diff --git a/meilidb-core/src/criterion/exact.rs b/meilidb-core/src/criterion/exact.rs index b76e9ace5..b038b9076 100644 --- a/meilidb-core/src/criterion/exact.rs +++ b/meilidb-core/src/criterion/exact.rs @@ -36,4 +36,8 @@ impl Criterion for Exact { lhs.cmp(&rhs).reverse() } + + fn name(&self) -> &'static str { + "Exact" + } } diff --git a/meilidb-core/src/criterion/mod.rs b/meilidb-core/src/criterion/mod.rs index 2ad3a183c..2ed5a54ba 100644 --- a/meilidb-core/src/criterion/mod.rs +++ b/meilidb-core/src/criterion/mod.rs @@ -22,6 +22,9 @@ pub use self::{ pub trait Criterion: Send + Sync { fn evaluate(&self, lhs: &RawDocument, rhs: &RawDocument) -> Ordering; + #[inline] + fn name(&self) -> &'static str; + #[inline] fn eq(&self, lhs: &RawDocument, rhs: &RawDocument) -> bool { self.evaluate(lhs, rhs) == Ordering::Equal @@ -33,6 +36,10 @@ impl<'a, T: Criterion + ?Sized + Send + Sync> Criterion for &'a T { (**self).evaluate(lhs, rhs) } + fn name(&self) -> &'static str { + (**self).name() + } + fn eq(&self, lhs: &RawDocument, rhs: &RawDocument) -> bool { (**self).eq(lhs, rhs) } @@ -43,6 +50,10 @@ impl Criterion for Box { (**self).evaluate(lhs, rhs) } + fn name(&self) -> &'static str { + (**self).name() + } + fn eq(&self, lhs: &RawDocument, rhs: &RawDocument) -> bool { (**self).eq(lhs, rhs) } diff --git a/meilidb-core/src/criterion/number_of_words.rs b/meilidb-core/src/criterion/number_of_words.rs index 798123e6a..43095a066 100644 --- a/meilidb-core/src/criterion/number_of_words.rs +++ b/meilidb-core/src/criterion/number_of_words.rs @@ -24,4 +24,8 @@ impl Criterion for NumberOfWords { lhs.cmp(&rhs).reverse() } + + fn name(&self) -> &'static str { + "NumberOfWords" + } } diff --git a/meilidb-core/src/criterion/sum_of_typos.rs b/meilidb-core/src/criterion/sum_of_typos.rs index 714766a20..d5cd75f08 100644 --- a/meilidb-core/src/criterion/sum_of_typos.rs +++ b/meilidb-core/src/criterion/sum_of_typos.rs @@ -53,6 +53,10 @@ impl Criterion for SumOfTypos { lhs.cmp(&rhs).reverse() } + + fn name(&self) -> &'static str { + "SumOfTypos" + } } #[cfg(test)] diff --git a/meilidb-core/src/criterion/sum_of_words_attribute.rs b/meilidb-core/src/criterion/sum_of_words_attribute.rs index a46787797..f5a3c3576 100644 --- a/meilidb-core/src/criterion/sum_of_words_attribute.rs +++ b/meilidb-core/src/criterion/sum_of_words_attribute.rs @@ -35,4 +35,8 @@ impl Criterion for SumOfWordsAttribute { lhs.cmp(&rhs) } + + fn name(&self) -> &'static str { + "SumOfWordsAttribute" + } } diff --git a/meilidb-core/src/criterion/sum_of_words_position.rs b/meilidb-core/src/criterion/sum_of_words_position.rs index 86f4e93fa..e365aef3b 100644 --- a/meilidb-core/src/criterion/sum_of_words_position.rs +++ b/meilidb-core/src/criterion/sum_of_words_position.rs @@ -35,4 +35,8 @@ impl Criterion for SumOfWordsPosition { lhs.cmp(&rhs) } + + fn name(&self) -> &'static str { + "SumOfWordsPosition" + } } diff --git a/meilidb-core/src/criterion/words_proximity.rs b/meilidb-core/src/criterion/words_proximity.rs index fc6c8bb31..10f167bef 100644 --- a/meilidb-core/src/criterion/words_proximity.rs +++ b/meilidb-core/src/criterion/words_proximity.rs @@ -98,6 +98,10 @@ impl Criterion for WordsProximity { lhs.cmp(&rhs) } + + fn name(&self) -> &'static str { + "WordsProximity" + } } #[cfg(test)] diff --git a/meilidb-core/src/query_builder.rs b/meilidb-core/src/query_builder.rs index 058c61ecc..b32fa3902 100644 --- a/meilidb-core/src/query_builder.rs +++ b/meilidb-core/src/query_builder.rs @@ -157,13 +157,11 @@ where S: Store, let mut groups = vec![documents.as_mut_slice()]; - 'criteria: for (ci, criterion) in self.criteria.as_ref().iter().enumerate() { + 'criteria: for criterion in self.criteria.as_ref() { let tmp_groups = mem::replace(&mut groups, Vec::new()); let mut documents_seen = 0; for group in tmp_groups { - info!("criterion {}, documents group of size {}", ci, group.len()); - // if this group does not overlap with the requested range, // push it without sorting and splitting it if documents_seen + group.len() < range.start { @@ -174,9 +172,11 @@ where S: Store, let start = Instant::now(); group.par_sort_unstable_by(|a, b| criterion.evaluate(a, b)); - info!("criterion {} sort took {:.2?}", ci, start.elapsed()); + info!("criterion {} sort took {:.2?}", criterion.name(), start.elapsed()); for group in group.binary_group_by_mut(|a, b| criterion.eq(a, b)) { + info!("criterion {} produced a group of size {}", criterion.name(), group.len()); + documents_seen += group.len(); groups.push(group); @@ -237,14 +237,12 @@ where S: Store, let mut distinct_map = DistinctMap::new(self.size); let mut distinct_raw_offset = 0; - 'criteria: for (ci, criterion) in self.inner.criteria.as_ref().iter().enumerate() { + 'criteria: for criterion in self.inner.criteria.as_ref() { let tmp_groups = mem::replace(&mut groups, Vec::new()); let mut buf_distinct = BufferedDistinctMap::new(&mut distinct_map); let mut documents_seen = 0; for group in tmp_groups { - info!("criterion {}, documents group of size {}", ci, group.len()); - // if this group does not overlap with the requested range, // push it without sorting and splitting it if documents_seen + group.len() < distinct_raw_offset { @@ -255,7 +253,7 @@ where S: Store, let start = Instant::now(); group.par_sort_unstable_by(|a, b| criterion.evaluate(a, b)); - info!("criterion {} sort took {:.2?}", ci, start.elapsed()); + info!("criterion {} sort took {:.2?}", criterion.name(), start.elapsed()); for group in group.binary_group_by_mut(|a, b| criterion.eq(a, b)) { // we must compute the real distinguished len of this sub-group @@ -282,6 +280,8 @@ where S: Store, if buf_distinct.len() >= range.end { break } } + info!("criterion {} produced a group of size {}", criterion.name(), group.len()); + documents_seen += group.len(); groups.push(group);