Struct MultiMatcher

Source
pub struct MultiMatcher<Q, C> { /* private fields */ }

Implementations§

Source§

impl<Q: Clone + Debug, C: Clone + Debug + PartialEq> MultiMatcher<Q, C>

Source

pub fn new() -> Self

Examples found in repository?
examples/multimatcher.rs (line 67)
56fn main() {
57    // Create two matchers with different metrics and thresholds
58    let matcher1 = Matcher::<String, String>::new()
59        .add(LevenshteinMetric, 1.0)
60        .threshold(0.6);
61
62    let matcher2 = Matcher::<String, String>::new()
63        .add(JaccardMetric, 1.0)
64        .threshold(0.4);
65
66    // Combine them into a MultiMatcher
67    let multi_matcher = MultiMatcher::<String, String>::new()
68        .add(matcher1)
69        .add(matcher2)
70        .threshold(0.5);
71
72    // Define the query and candidate strings
73    let query = String::from("example");
74    let candidates = vec![
75        String::from("example"),
76        String::from("examp"),
77        String::from("test"),
78    ];
79
80    // Find matches with a limit of 2
81    println!("MultiMatcher Example");
82    println!("===================");
83    let matches = multi_matcher.find_limit(&query, &candidates, 2);
84    println!("Matches found: {}", matches.len());
85    for (i, m) in matches.iter().enumerate() {
86        println!(
87            "Match {}:\n  Score: {:.2}\n  Candidate: {}\n  Exact: {}",
88            i + 1, m.score, m.candidate, m.exact
89        );
90    }
91}
Source

pub fn add(self, matcher: Matcher<Q, C>) -> Self

Examples found in repository?
examples/multimatcher.rs (line 68)
56fn main() {
57    // Create two matchers with different metrics and thresholds
58    let matcher1 = Matcher::<String, String>::new()
59        .add(LevenshteinMetric, 1.0)
60        .threshold(0.6);
61
62    let matcher2 = Matcher::<String, String>::new()
63        .add(JaccardMetric, 1.0)
64        .threshold(0.4);
65
66    // Combine them into a MultiMatcher
67    let multi_matcher = MultiMatcher::<String, String>::new()
68        .add(matcher1)
69        .add(matcher2)
70        .threshold(0.5);
71
72    // Define the query and candidate strings
73    let query = String::from("example");
74    let candidates = vec![
75        String::from("example"),
76        String::from("examp"),
77        String::from("test"),
78    ];
79
80    // Find matches with a limit of 2
81    println!("MultiMatcher Example");
82    println!("===================");
83    let matches = multi_matcher.find_limit(&query, &candidates, 2);
84    println!("Matches found: {}", matches.len());
85    for (i, m) in matches.iter().enumerate() {
86        println!(
87            "Match {}:\n  Score: {:.2}\n  Candidate: {}\n  Exact: {}",
88            i + 1, m.score, m.candidate, m.exact
89        );
90    }
91}
Source

pub fn threshold(self, threshold: f64) -> Self

Examples found in repository?
examples/multimatcher.rs (line 70)
56fn main() {
57    // Create two matchers with different metrics and thresholds
58    let matcher1 = Matcher::<String, String>::new()
59        .add(LevenshteinMetric, 1.0)
60        .threshold(0.6);
61
62    let matcher2 = Matcher::<String, String>::new()
63        .add(JaccardMetric, 1.0)
64        .threshold(0.4);
65
66    // Combine them into a MultiMatcher
67    let multi_matcher = MultiMatcher::<String, String>::new()
68        .add(matcher1)
69        .add(matcher2)
70        .threshold(0.5);
71
72    // Define the query and candidate strings
73    let query = String::from("example");
74    let candidates = vec![
75        String::from("example"),
76        String::from("examp"),
77        String::from("test"),
78    ];
79
80    // Find matches with a limit of 2
81    println!("MultiMatcher Example");
82    println!("===================");
83    let matches = multi_matcher.find_limit(&query, &candidates, 2);
84    println!("Matches found: {}", matches.len());
85    for (i, m) in matches.iter().enumerate() {
86        println!(
87            "Match {}:\n  Score: {:.2}\n  Candidate: {}\n  Exact: {}",
88            i + 1, m.score, m.candidate, m.exact
89        );
90    }
91}
Source

pub fn best(&self, query: &Q, candidates: &[C]) -> Option<Match<Q, C>>

Source

pub fn find(&self, query: &Q, candidates: &[C]) -> Vec<Match<Q, C>>

Source

pub fn find_limit( &self, query: &Q, candidates: &[C], limit: usize, ) -> Vec<Match<Q, C>>

Examples found in repository?
examples/multimatcher.rs (line 83)
56fn main() {
57    // Create two matchers with different metrics and thresholds
58    let matcher1 = Matcher::<String, String>::new()
59        .add(LevenshteinMetric, 1.0)
60        .threshold(0.6);
61
62    let matcher2 = Matcher::<String, String>::new()
63        .add(JaccardMetric, 1.0)
64        .threshold(0.4);
65
66    // Combine them into a MultiMatcher
67    let multi_matcher = MultiMatcher::<String, String>::new()
68        .add(matcher1)
69        .add(matcher2)
70        .threshold(0.5);
71
72    // Define the query and candidate strings
73    let query = String::from("example");
74    let candidates = vec![
75        String::from("example"),
76        String::from("examp"),
77        String::from("test"),
78    ];
79
80    // Find matches with a limit of 2
81    println!("MultiMatcher Example");
82    println!("===================");
83    let matches = multi_matcher.find_limit(&query, &candidates, 2);
84    println!("Matches found: {}", matches.len());
85    for (i, m) in matches.iter().enumerate() {
86        println!(
87            "Match {}:\n  Score: {:.2}\n  Candidate: {}\n  Exact: {}",
88            i + 1, m.score, m.candidate, m.exact
89        );
90    }
91}

Trait Implementations§

Source§

impl<Q, C> Default for MultiMatcher<Q, C>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Q, C> Freeze for MultiMatcher<Q, C>

§

impl<Q, C> !RefUnwindSafe for MultiMatcher<Q, C>

§

impl<Q, C> !Send for MultiMatcher<Q, C>

§

impl<Q, C> !Sync for MultiMatcher<Q, C>

§

impl<Q, C> Unpin for MultiMatcher<Q, C>

§

impl<Q, C> !UnwindSafe for MultiMatcher<Q, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.