mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-24 21:50:07 +01:00
feat: Introduce the Criterion::name
to allow better debugging
This commit is contained in:
parent
08d89053da
commit
8c71473498
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -36,4 +36,8 @@ impl Criterion for Exact {
|
||||
|
||||
lhs.cmp(&rhs).reverse()
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Exact"
|
||||
}
|
||||
}
|
||||
|
@ -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<T: Criterion + ?Sized> Criterion for Box<T> {
|
||||
(**self).evaluate(lhs, rhs)
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
(**self).name()
|
||||
}
|
||||
|
||||
fn eq(&self, lhs: &RawDocument, rhs: &RawDocument) -> bool {
|
||||
(**self).eq(lhs, rhs)
|
||||
}
|
||||
|
@ -24,4 +24,8 @@ impl Criterion for NumberOfWords {
|
||||
|
||||
lhs.cmp(&rhs).reverse()
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"NumberOfWords"
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,10 @@ impl Criterion for SumOfTypos {
|
||||
|
||||
lhs.cmp(&rhs).reverse()
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"SumOfTypos"
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -35,4 +35,8 @@ impl Criterion for SumOfWordsAttribute {
|
||||
|
||||
lhs.cmp(&rhs)
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"SumOfWordsAttribute"
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,8 @@ impl Criterion for SumOfWordsPosition {
|
||||
|
||||
lhs.cmp(&rhs)
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"SumOfWordsPosition"
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,10 @@ impl Criterion for WordsProximity {
|
||||
|
||||
lhs.cmp(&rhs)
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"WordsProximity"
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user