ivy.nvim/rust/matcher.rs
Ade Attwood f4a65a574c perf: add instance prop of SkimMatcherV2
This is so we are not crating an new instance of this each time we are
scoring a match.
2022-08-25 20:19:09 +01:00

25 lines
591 B
Rust

use fuzzy_matcher::FuzzyMatcher;
use fuzzy_matcher::skim::SkimMatcherV2;
pub struct Matcher {
/// The search pattern that we want to match against some text
pub pattern: String,
matcher: SkimMatcherV2,
}
impl Matcher {
pub fn new(pattern: String) -> Self {
return Self {
pattern,
matcher: SkimMatcherV2::default(),
}
}
pub fn score(self: &Self, text: String) -> i64 {
if let Some((score, _indices)) = self.matcher.fuzzy_indices(&text, &self.pattern) {
return score;
}
return 0;
}
}