feat: Introduce the Criterion trait

This commit is contained in:
Clément Renault
2018-10-11 14:04:41 +02:00
parent c56c35b45b
commit 8cd07462aa
11 changed files with 209 additions and 218 deletions

View File

@ -2,6 +2,7 @@ use std::cmp::Ordering;
use group_by::GroupBy;
use crate::Match;
use crate::rank::{match_query_index, Document};
use crate::rank::criterion::Criterion;
#[inline]
fn sum_matches_attribute_index(matches: &[Match]) -> u32 {
@ -12,10 +13,14 @@ fn sum_matches_attribute_index(matches: &[Match]) -> u32 {
}).sum()
}
#[inline]
pub fn sum_of_words_position(lhs: &Document, rhs: &Document) -> Ordering {
let lhs = sum_matches_attribute_index(&lhs.matches);
let rhs = sum_matches_attribute_index(&rhs.matches);
#[derive(Debug, Clone, Copy)]
pub struct SumOfWordsPosition;
lhs.cmp(&rhs)
impl Criterion for SumOfWordsPosition {
fn evaluate(&self, lhs: &Document, rhs: &Document) -> Ordering {
let lhs = sum_matches_attribute_index(&lhs.matches);
let rhs = sum_matches_attribute_index(&rhs.matches);
lhs.cmp(&rhs)
}
}