get_top_n

Function get_top_n 

Source
pub fn get_top_n<'a>(
    query: &str,
    choices: &[&'a str],
    cutoff: Option<f64>,
    n: Option<usize>,
    processor: Option<&dyn StringProcessor>,
    scorer: Option<&dyn SimilarityMetric>,
) -> Vec<&'a str>
Expand description

Returns a list of the best matches to a collection of choices.

This is a convenience function for getting the choices with the highest scores.

§Arguments

  • query - A string to match against.
  • choices - A list of choices to compare against the query.
  • cutoff - A score threshold. No matches with a score less than this number will be returned. Defaults to 0.7.
  • n - Optional maximum for the number of elements returned. Defaults to 3.
  • processor - Optional function for transforming choices before matching. If not provided, NullStringProcessor is used.
  • scorer - Optional scoring function for extract(). If not provided, SequenceMatcher is used.

§Returns

  • A vector of the top ‘n’ matches from the given choices.

§Example

extern crate fuzzt;
use fuzzt::{algorithms::NormalizedLevenshtein, get_top_n, processors::NullStringProcessor};

let matches = get_top_n(
    "apple",
    &["apply", "apples", "ape", "applet", "applesauce"],
    Some(0.8),
    Some(3),
    Some(&NullStringProcessor),
    Some(&NormalizedLevenshtein),
);
assert_eq!(matches, ["apples", "applet", "apply"]);