ivy.nvim/rust/sorter.rs
Xymist de41712291 Return to using minimum_score
- Update the provided `minimum_score` in `sorter::Option::new` to match
  what was being used in `sort_strings`
- Use the `minimum_score` value instead of a hardcoded number

This seems like functionality that was either intended and not added, or
added and then part removed. Either way the performance impact is
minimal and it's a nice idea.
2022-08-26 16:40:12 +01:00

36 lines
816 B
Rust

use super::matcher;
use rayon::prelude::*;
pub struct Match {
pub score: i64,
pub content: String,
}
pub struct Options {
pub pattern: String,
pub minimum_score: i64,
}
impl Options {
pub fn new(pattern: String) -> Self {
Self {
pattern,
minimum_score: 25,
}
}
}
pub fn sort_strings(options: Options, strings: Vec<String>) -> Vec<Match> {
let matcher = matcher::Matcher::new(options.pattern);
let mut matches = strings
.into_par_iter()
.map(|candidate| Match {
score: matcher.score(candidate.as_str()),
content: candidate,
})
.filter(|m| m.score > options.minimum_score)
.collect::<Vec<Match>>();
matches.par_sort_unstable_by(|a, b| a.score.cmp(&b.score));
matches
}