42 lines
999 B
Rust
Raw Normal View History

use std::cmp::Ordering;
use slice_group_by::GroupBy;
2018-10-11 14:04:41 +02:00
use crate::rank::criterion::Criterion;
use crate::rank::RawDocument;
2018-08-25 13:15:04 +02:00
#[inline]
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
for group in query_index.linear_group() {
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;
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-10-11 14:04:41 +02:00
lhs.cmp(&rhs).reverse()
}
}