-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out matcher and filter crate (#463)
* Split out matcher crate * Use matcher crate in filter * Split out filter crate * Move extracted_fzy to matcher/extracted_fzy * Commit cmd/filter.rs * Move process_top_items() to printer * Fix test * Printer sync/dync_filter_results * Move macros to utility * . * . * .
- Loading branch information
1 parent
ee02a6f
commit 41dc711
Showing
29 changed files
with
633 additions
and
521 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
[workspace] | ||
|
||
members = [ | ||
"extracted_fzy", | ||
"fuzzy_filter", | ||
"icon", | ||
"maple_cli", | ||
"pattern", | ||
"printer", | ||
"stdio_server", | ||
"utility", | ||
"upgrade", | ||
"matcher", | ||
"matcher/extracted_fzy", | ||
"filter", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
[package] | ||
name = "fuzzy_filter" | ||
name = "filter" | ||
version = "0.1.0" | ||
authors = ["Liu-Cheng Xu <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT" | ||
publish = false | ||
homepage = "https://github.com/liuchengxu/vim-clap" | ||
categories = ["Fuzzy Filter Library"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rayon = "1.2" | ||
anyhow = "1.0" | ||
structopt = "0.3" | ||
fuzzy-matcher = "0.3.1" | ||
|
||
serde_json = "1.0" | ||
serde = { package = "serde", version = "1.0", features = ["derive"] } | ||
subprocess = { git = "https://github.com/hniksic/rust-subprocess", optional = true } | ||
|
||
extracted_fzy = { path = "../extracted_fzy" } | ||
pattern = { path = "../pattern" } | ||
icon = { path = "../icon" } | ||
matcher = { path = "../matcher" } | ||
printer = { path = "../printer" } | ||
utility = { path = "../utility" } | ||
|
||
[features] | ||
default = ["enable_dyn"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! This crate provides the feature of filtering a stream of lines. | ||
//! | ||
//! Given a stream of lines: | ||
//! | ||
//! 1. apply the matcher algorithm on each of them. | ||
//! 2. sort the all lines with a match result. | ||
//! 3. print the top rated filtered lines to stdout. | ||
|
||
mod dynamic; | ||
mod source; | ||
|
||
use anyhow::Result; | ||
use matcher::Algo; | ||
use rayon::prelude::*; | ||
|
||
pub use dynamic::dyn_run; | ||
pub use matcher; | ||
pub use source::Source; | ||
#[cfg(feature = "enable_dyn")] | ||
pub use subprocess; | ||
|
||
/// Tuple of (matched line text, filtering score, indices of matched elements) | ||
pub type FilterResult = (String, i64, Vec<usize>); | ||
|
||
/// Returns the ranked results after applying the matcher algo | ||
/// given the query String and filtering source. | ||
pub fn sync_run<I: Iterator<Item = String>>( | ||
query: &str, | ||
source: Source<I>, | ||
algo: Algo, | ||
) -> Result<Vec<FilterResult>> { | ||
let mut ranked = source.filter(algo, query)?; | ||
|
||
ranked.par_sort_unstable_by(|(_, v1, _), (_, v2, _)| v2.partial_cmp(&v1).unwrap()); | ||
|
||
Ok(ranked) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.