numeric/
numeric.rs

1use matchete::{Matcher, Custom};
2
3fn main() {
4    // Create a numeric similarity metric
5    let numeric_metric = Custom::new(|query: &f64, candidate: &f64| {
6        let diff = (query - candidate).abs();
7        let max_val = query.abs().max(candidate.abs());
8        if max_val == 0.0 { 1.0 } else { 1.0 - (diff / (max_val + 1.0)) }
9    });
10
11    // Create a matcher for f64 numbers
12    let matcher = Matcher::<f64, f64>::new()
13        .add(numeric_metric, 1.0)
14        .threshold(0.8);
15
16    // Define the query and candidate numbers
17    let query = 42.0;
18    let candidates = vec![40.0, 45.0, 100.0];
19
20    // Find all matches
21    println!("Numeric Matching Example");
22    println!("=======================");
23    let matches = matcher.find(&query, &candidates);
24    println!("Matches found: {}", matches.len());
25    for (i, m) in matches.iter().enumerate() {
26        println!(
27            "Match {}:\n  Score: {:.2}\n  Candidate: {}\n  Exact: {}",
28            i + 1, m.score, m.candidate, m.exact
29        );
30    }
31}