pub fn rank<'a>(query: &str, subjects: Vec<&'a str>) -> Vec<(f64, &'a str)>
Expand description
Ranks a list of strings based on their similarity to a query string using the compare
function.
§Arguments
query
- A reference to the query string.subjects
- A vector of references to the subject strings to be ranked.
§Returns
- A vector of tuples containing the similarity score and the corresponding subject string, sorted by score in descending order.
§Examples
let query = "Ad";
let subjects = vec!["Ad_Fields", "Users", "Aged_groups"];
let result = rank(query, subjects);
assert_eq!(result, vec![(2.0, "Ad_Fields"), (1.0, "Aged_groups"), (0.0, "Users")]);