34 lines
769 B
Rust
Raw Normal View History

use std::cmp::Ordering;
use std::ops::Deref;
use rocksdb::DB;
use crate::rank::{Document, Matches};
2018-10-11 14:04:41 +02:00
use crate::rank::criterion::Criterion;
use crate::database::DatabaseView;
use crate::Match;
2018-08-25 13:15:04 +02:00
#[inline]
fn contains_exact(matches: &[Match]) -> bool {
matches.iter().any(|m| m.is_exact)
}
#[inline]
fn number_exact_matches(matches: &Matches) -> usize {
matches.query_index_groups().map(contains_exact).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<D> Criterion<D> for Exact
where D: Deref<Target=DB>
{
fn evaluate(&self, lhs: &Document, rhs: &Document, _: &DatabaseView<D>) -> Ordering {
2018-10-11 14:04:41 +02:00
let lhs = number_exact_matches(&lhs.matches);
let rhs = number_exact_matches(&rhs.matches);
2018-10-11 14:04:41 +02:00
lhs.cmp(&rhs).reverse()
}
}