#[derive(Debug, Clone, PartialEq)]
pub struct BM25Params {
pub k1: f64,
pub b: f64,
pub delta: f64,
}
impl Default for BM25Params {
fn default() -> Self {
Self {
k1: 1.2,
b: 0.75,
delta: 1.0,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct FieldWeights {
pub title: f64,
pub body: f64,
pub description: f64,
pub tags: f64,
}
impl Default for FieldWeights {
fn default() -> Self {
Self {
title: 3.0,
body: 1.0,
description: 2.0,
tags: 2.5,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_bm25_params_default() {
let params = BM25Params::default();
assert_eq!(params.k1, 1.2);
assert_eq!(params.b, 0.75);
assert_eq!(params.delta, 1.0);
}
#[test]
fn test_field_weights_default() {
let weights = FieldWeights::default();
assert_eq!(weights.title, 3.0);
assert_eq!(weights.body, 1.0);
assert_eq!(weights.description, 2.0);
assert_eq!(weights.tags, 2.5);
}
#[test]
fn test_bm25_params_custom() {
let params = BM25Params {
k1: 1.5,
b: 0.8,
delta: 0.5,
};
assert_eq!(params.k1, 1.5);
assert_eq!(params.b, 0.8);
assert_eq!(params.delta, 0.5);
}
#[test]
fn test_field_weights_custom() {
let weights = FieldWeights {
title: 4.0,
body: 1.5,
description: 2.5,
tags: 3.0,
};
assert_eq!(weights.title, 4.0);
assert_eq!(weights.body, 1.5);
assert_eq!(weights.description, 2.5);
assert_eq!(weights.tags, 3.0);
}
}