pub struct Composite<Q, C> { /* private fields */ }Implementations§
Source§impl<Q, C> Composite<Q, C>
impl<Q, C> Composite<Q, C>
Sourcepub fn new(strategy: Strategy) -> Self
pub fn new(strategy: Strategy) -> Self
Examples found in repository?
examples/multimetric.rs (line 58)
56fn main() {
57 // Create a composite metric with weighted strategy
58 let composite_metric = Composite::<String, String>::new(Strategy::Weighted(vec![0.6, 0.4]))
59 .add(LevenshteinMetric)
60 .add(JaccardMetric);
61
62 // Create a matcher with the composite metric
63 let matcher = Matcher::<String, String>::new()
64 .add(composite_metric, 1.0)
65 .threshold(0.5);
66
67 // Define the query and candidate strings
68 let query = String::from("hello world");
69 let candidates = vec![
70 String::from("hello"),
71 String::from("hello there"),
72 String::from("world"),
73 ];
74
75 // Find matches with a limit of 2
76 println!("Multiple Metrics Example");
77 println!("=======================");
78 let matches = matcher.find_limit(&query, &candidates, 2);
79 println!("Matches found: {}", matches.len());
80 for (i, m) in matches.iter().enumerate() {
81 println!(
82 "Match {}:\n Score: {:.2}\n Candidate: {}\n Exact: {}",
83 i + 1, m.score, m.candidate, m.exact
84 );
85 }
86}Sourcepub fn add<M: Similarity<Q, C> + 'static>(self, metric: M) -> Self
pub fn add<M: Similarity<Q, C> + 'static>(self, metric: M) -> Self
Examples found in repository?
examples/multimetric.rs (line 59)
56fn main() {
57 // Create a composite metric with weighted strategy
58 let composite_metric = Composite::<String, String>::new(Strategy::Weighted(vec![0.6, 0.4]))
59 .add(LevenshteinMetric)
60 .add(JaccardMetric);
61
62 // Create a matcher with the composite metric
63 let matcher = Matcher::<String, String>::new()
64 .add(composite_metric, 1.0)
65 .threshold(0.5);
66
67 // Define the query and candidate strings
68 let query = String::from("hello world");
69 let candidates = vec![
70 String::from("hello"),
71 String::from("hello there"),
72 String::from("world"),
73 ];
74
75 // Find matches with a limit of 2
76 println!("Multiple Metrics Example");
77 println!("=======================");
78 let matches = matcher.find_limit(&query, &candidates, 2);
79 println!("Matches found: {}", matches.len());
80 for (i, m) in matches.iter().enumerate() {
81 println!(
82 "Match {}:\n Score: {:.2}\n Candidate: {}\n Exact: {}",
83 i + 1, m.score, m.candidate, m.exact
84 );
85 }
86}Trait Implementations§
Auto Trait Implementations§
impl<Q, C> Freeze for Composite<Q, C>
impl<Q, C> !RefUnwindSafe for Composite<Q, C>
impl<Q, C> !Send for Composite<Q, C>
impl<Q, C> !Sync for Composite<Q, C>
impl<Q, C> Unpin for Composite<Q, C>
impl<Q, C> !UnwindSafe for Composite<Q, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more