mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Move crates under a sub folder to clean up the code
This commit is contained in:
parent
30f3c30389
commit
9c1e54a2c8
1062 changed files with 19 additions and 20 deletions
37
crates/milli/src/proximity.rs
Normal file
37
crates/milli/src/proximity.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use std::cmp;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{relative_from_absolute_position, Position};
|
||||
|
||||
pub const MAX_DISTANCE: u32 = 4;
|
||||
|
||||
pub fn index_proximity(lhs: u32, rhs: u32) -> u32 {
|
||||
if lhs <= rhs {
|
||||
cmp::min(rhs - lhs, MAX_DISTANCE)
|
||||
} else {
|
||||
cmp::min((lhs - rhs) + 1, MAX_DISTANCE)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn positions_proximity(lhs: Position, rhs: Position) -> u32 {
|
||||
let (lhs_attr, lhs_index) = relative_from_absolute_position(lhs);
|
||||
let (rhs_attr, rhs_index) = relative_from_absolute_position(rhs);
|
||||
if lhs_attr != rhs_attr {
|
||||
MAX_DISTANCE
|
||||
} else {
|
||||
index_proximity(lhs_index as u32, rhs_index as u32)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn path_proximity(path: &[Position]) -> u32 {
|
||||
path.windows(2).map(|w| positions_proximity(w[0], w[1])).sum::<u32>()
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum ProximityPrecision {
|
||||
#[default]
|
||||
ByWord,
|
||||
ByAttribute,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue