2018-07-07 14:43:29 +02:00
|
|
|
use std::cmp::Ordering;
|
2019-01-30 16:30:27 +01:00
|
|
|
use slice_group_by::GroupBy;
|
2019-02-24 19:44:24 +01:00
|
|
|
use crate::criterion::Criterion;
|
|
|
|
use crate::RawDocument;
|
2018-07-07 14:43:29 +02:00
|
|
|
|
2018-08-25 13:15:04 +02:00
|
|
|
#[inline]
|
2019-02-02 14:22:31 +01:00
|
|
|
fn number_exact_matches(query_index: &[u32], is_exact: &[bool]) -> usize {
|
|
|
|
let mut count = 0;
|
|
|
|
let mut index = 0;
|
2018-08-25 13:15:04 +02:00
|
|
|
|
2019-02-12 15:43:43 +01:00
|
|
|
for group in query_index.linear_group() {
|
2019-02-02 14:22:31 +01:00
|
|
|
let len = group.len();
|
|
|
|
count += is_exact[index..index + len].contains(&true) as usize;
|
|
|
|
index += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
count
|
2018-08-25 13:15:04 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 14:04:41 +02:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
pub struct Exact;
|
|
|
|
|
2019-02-02 14:22:31 +01:00
|
|
|
impl Criterion for Exact {
|
|
|
|
fn evaluate(&self, lhs: &RawDocument, rhs: &RawDocument) -> Ordering {
|
|
|
|
let lhs = {
|
|
|
|
let query_index = lhs.query_index();
|
|
|
|
let is_exact = lhs.is_exact();
|
|
|
|
number_exact_matches(query_index, is_exact)
|
|
|
|
};
|
|
|
|
|
|
|
|
let rhs = {
|
|
|
|
let query_index = rhs.query_index();
|
|
|
|
let is_exact = rhs.is_exact();
|
|
|
|
number_exact_matches(query_index, is_exact)
|
|
|
|
};
|
2018-07-07 14:43:29 +02:00
|
|
|
|
2018-10-11 14:04:41 +02:00
|
|
|
lhs.cmp(&rhs).reverse()
|
|
|
|
}
|
2018-07-07 14:43:29 +02:00
|
|
|
}
|