Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F30970
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/rust/matcher.rs b/rust/matcher.rs
index cbbf6d7..59a15b1 100644
--- a/rust/matcher.rs
+++ b/rust/matcher.rs
@@ -1,24 +1,23 @@
use fuzzy_matcher::skim::SkimMatcherV2;
use fuzzy_matcher::FuzzyMatcher;
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 {
Self {
pattern,
matcher: SkimMatcherV2::default(),
}
}
pub fn score(&self, text: &str) -> i64 {
self.matcher
- .fuzzy_indices(text, &self.pattern)
- .map(|(score, _indices)| score)
+ .fuzzy_match(text, &self.pattern)
.unwrap_or_default()
}
}
diff --git a/rust/sorter.rs b/rust/sorter.rs
index f81f622..2778789 100644
--- a/rust/sorter.rs
+++ b/rust/sorter.rs
@@ -1,36 +1,43 @@
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_map(|candidate| {
+ let score = matcher.score(candidate.as_str());
+ if score > options.minimum_score {
+ return None;
+ }
+
+ Some(Match {
+ score,
+ 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
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Sep 10, 5:07 PM (7 h, 44 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9054
Default Alt Text
(2 KB)
Attached To
Mode
R1 ivy.nvim
Attached
Detach File
Event Timeline
Log In to Comment