mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-30 02:09:57 +00:00
feat: Introduce the Criteria struct
This commit is contained in:
21
src/rank/criterion/sum_of_words_position.rs
Normal file
21
src/rank/criterion/sum_of_words_position.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use std::cmp::Ordering;
|
||||
use group_by::GroupBy;
|
||||
use crate::Match;
|
||||
use crate::rank::{match_query_index, Document};
|
||||
|
||||
#[inline]
|
||||
fn sum_matches_attribute_index(matches: &[Match]) -> u32 {
|
||||
// note that GroupBy will never return an empty group
|
||||
// so we can do this assumption safely
|
||||
GroupBy::new(matches, match_query_index).map(|group| unsafe {
|
||||
group.get_unchecked(0).attribute_index
|
||||
}).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);
|
||||
|
||||
lhs.cmp(&rhs)
|
||||
}
|
Reference in New Issue
Block a user