2018-07-07 14:43:29 +02:00
|
|
|
use std::cmp::Ordering;
|
|
|
|
use Match;
|
|
|
|
use rank::{match_query_index, Document};
|
|
|
|
use group_by::GroupBy;
|
|
|
|
|
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: &[Match]) -> usize {
|
|
|
|
GroupBy::new(matches, match_query_index).map(contains_exact).count()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2018-07-07 14:43:29 +02:00
|
|
|
pub fn exact(lhs: &Document, rhs: &Document) -> Ordering {
|
2018-08-25 13:15:04 +02:00
|
|
|
let lhs = number_exact_matches(&lhs.matches);
|
|
|
|
let rhs = number_exact_matches(&rhs.matches);
|
2018-07-07 14:43:29 +02:00
|
|
|
|
2018-08-25 13:15:04 +02:00
|
|
|
lhs.cmp(&rhs)
|
2018-07-07 14:43:29 +02:00
|
|
|
}
|