fuzzy_match_rank

Function fuzzy_match_rank 

Source
pub fn fuzzy_match_rank(name: &str, query: &str) -> Option<i64>
Expand description

Rank how well a package name matches a query using fuzzy matching (fzf-style).

Inputs:

  • name: Package name to match against
  • query: Query string to match

Output:

  • Some(score) if the query matches the name (higher score = better match), None if no match

Details:

  • Uses fuzzy_matcher::skim::SkimMatcherV2 for fzf-style fuzzy matching
  • Returns scores where higher values indicate better matches
  • Returns None when the query doesn’t match at all
  • For performance-critical code that calls this function multiple times with the same query, consider using fuzzy_match_rank_with_matcher instead to reuse the matcher instance

§Examples

use pacsea::util::fuzzy_match_rank;

// Fuzzy matching a package name during search (e.g., user types "rg" for "ripgrep")
let score = fuzzy_match_rank("ripgrep", "rg");
assert!(score.is_some()); // Should match and return a score
assert!(score.unwrap() > 0); // Higher score means better match

// Another common search: "fz" matching "fzf" (a command-line fuzzy finder)
let fzf_score = fuzzy_match_rank("fzf", "fz");
assert!(fzf_score.is_some());

// Exact match should have the highest score
let exact_score = fuzzy_match_rank("pacman", "pacman");
let partial_score = fuzzy_match_rank("pacman", "pac");
assert!(exact_score.unwrap() > partial_score.unwrap());

// No match returns None (e.g., searching "xyz" for "linux")
assert_eq!(fuzzy_match_rank("linux", "xyz"), None);

// Empty or whitespace-only query returns None
assert_eq!(fuzzy_match_rank("vim", ""), None);
assert_eq!(fuzzy_match_rank("neovim", "   "), None);