Compare commits
1 Commits
3b2641dd14
...
849bc8a5f2
Author | SHA1 | Date | |
---|---|---|---|
|
849bc8a5f2 |
@ -12,7 +12,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- implement naive fuzzy matcher
|
- implement naive fuzzy matcher
|
||||||
|
|
||||||
### Other
|
### Other
|
||||||
- refactor fuzzy match into own function
|
|
||||||
- cleanup warnings
|
- cleanup warnings
|
||||||
- move fuzzy search out of command
|
- move fuzzy search out of command
|
||||||
- refactor/matcher move to a separate file
|
- refactor/matcher move to a separate file
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
use std::collections::BTreeMap;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::App,
|
app::App, cache::CacheApp, fuzzy_matcher::FuzzyMatcherApp, projects_list::ProjectsListApp,
|
||||||
cache::CacheApp,
|
|
||||||
fuzzy_matcher::{FuzzyMatcher, FuzzyMatcherApp},
|
|
||||||
git_provider::Repository,
|
|
||||||
projects_list::ProjectsListApp,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -37,11 +31,16 @@ impl RootCommand {
|
|||||||
None => todo!(),
|
None => todo!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let matched_repos = self
|
let haystack = repositories
|
||||||
.app
|
.iter()
|
||||||
.fuzzy_matcher()
|
.map(|r| r.to_rel_path().display().to_string())
|
||||||
.match_repositories(&needle, &repositories);
|
.collect::<Vec<_>>();
|
||||||
let res = matched_repos.iter().take(10).rev().collect::<Vec<_>>();
|
|
||||||
|
let haystack = haystack.as_str_vec();
|
||||||
|
|
||||||
|
let res = self.app.fuzzy_matcher().match_pattern(&needle, &haystack);
|
||||||
|
|
||||||
|
let res = res.iter().take(10).rev().collect::<Vec<_>>();
|
||||||
|
|
||||||
for repo in res {
|
for repo in res {
|
||||||
tracing::debug!("repo: {:?}", repo);
|
tracing::debug!("repo: {:?}", repo);
|
||||||
@ -62,33 +61,3 @@ impl StringExt for Vec<String> {
|
|||||||
self.iter().map(|r| r.as_ref()).collect()
|
self.iter().map(|r| r.as_ref()).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StringExt for Vec<&String> {
|
|
||||||
fn as_str_vec(&self) -> Vec<&str> {
|
|
||||||
self.iter().map(|r| r.as_ref()).collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trait RepositoryMatcher {
|
|
||||||
fn match_repositories(&self, pattern: &str, repositories: &[Repository]) -> Vec<Repository>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RepositoryMatcher for FuzzyMatcher {
|
|
||||||
fn match_repositories(&self, pattern: &str, repositories: &[Repository]) -> Vec<Repository> {
|
|
||||||
let haystack = repositories
|
|
||||||
.iter()
|
|
||||||
.map(|r| (r.to_rel_path().display().to_string(), r))
|
|
||||||
.collect::<BTreeMap<_, _>>();
|
|
||||||
let haystack_keys = haystack.keys().collect::<Vec<_>>();
|
|
||||||
let haystack_keys = haystack_keys.as_str_vec();
|
|
||||||
|
|
||||||
let res = self.match_pattern(pattern, &haystack_keys);
|
|
||||||
|
|
||||||
let matched_repos = res
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|repo_key| haystack.get(repo_key).map(|r| (*r).to_owned()))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
matched_repos
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user