meilisearch/raptor/src/rank/sum_of_typos.rs

23 lines
639 B
Rust
Raw Normal View History

use std::cmp::Ordering;
use group_by::GroupBy;
use crate::Match;
use crate::rank::{match_query_index, Document};
2018-08-25 13:15:04 +02:00
#[inline]
fn sum_matches_typos(matches: &[Match]) -> u8 {
// note that GroupBy will never return an empty group
// so we can do this assumption safely
// matches must and will never be empty
2018-08-25 13:15:04 +02:00
GroupBy::new(matches, match_query_index).map(|group| unsafe {
group.get_unchecked(0).distance
}).min().unwrap()
2018-08-25 13:15:04 +02:00
}
#[inline]
pub fn sum_of_typos(lhs: &Document, rhs: &Document) -> Ordering {
2018-08-25 13:15:04 +02:00
let lhs = sum_matches_typos(&lhs.matches);
let rhs = sum_matches_typos(&rhs.matches);
2018-08-25 13:15:04 +02:00
lhs.cmp(&rhs)
}