mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-30 23:27:36 +01:00
30 lines
714 B
Rust
30 lines
714 B
Rust
use std::cmp::Ordering;
|
|
use std::ops::Deref;
|
|
|
|
use rocksdb::DB;
|
|
use group_by::GroupBy;
|
|
|
|
use crate::rank::{match_query_index, Document};
|
|
use crate::rank::criterion::Criterion;
|
|
use crate::database::DatabaseView;
|
|
use crate::Match;
|
|
|
|
#[inline]
|
|
fn number_of_query_words(matches: &[Match]) -> usize {
|
|
GroupBy::new(matches, match_query_index).count()
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct NumberOfWords;
|
|
|
|
impl<D> Criterion<D> for NumberOfWords
|
|
where D: Deref<Target=DB>
|
|
{
|
|
fn evaluate(&self, lhs: &Document, rhs: &Document, _: &DatabaseView<D>) -> Ordering {
|
|
let lhs = number_of_query_words(&lhs.matches);
|
|
let rhs = number_of_query_words(&rhs.matches);
|
|
|
|
lhs.cmp(&rhs).reverse()
|
|
}
|
|
}
|