Skip to content

Commit

Permalink
feat: added wild card and exact search in filter option #1240
Browse files Browse the repository at this point in the history
  • Loading branch information
hitenkoku committed Jan 11, 2024
1 parent 3d71dae commit 08ac11e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ memchr = "2.*"
num = "0.4.0"
indexmap = "2.*"
dialoguer = "*"
wildmatch = "2.*"

[profile.dev]
debug = 0
Expand Down
19 changes: 9 additions & 10 deletions src/timeline/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use csv::{QuoteStyle, WriterBuilder};
use downcast_rs::__std::process;
use hashbrown::{HashMap, HashSet};
use itertools::Itertools;
use nested::Nested;
use regex::Regex;
use std::fs::File;
use std::io::BufWriter;
use std::path::PathBuf;
use termcolor::{BufferWriter, Color, ColorChoice};
use wildmatch::WildMatch;

#[derive(Debug, Clone)]
pub struct EventSearch {
Expand Down Expand Up @@ -98,7 +98,7 @@ impl EventSearch {
fn filter_record(
&mut self,
record: &EvtxRecordInfo,
filter_rule: &HashMap<String, Nested<String>>,
filter_rule: &HashMap<String, Vec<WildMatch>>,

Check warning on line 101 in src/timeline/search.rs

View check run for this annotation

Codecov / codecov/patch

src/timeline/search.rs#L101

Added line #L101 was not covered by tests
eventkey_alias: &EventKeyAliasConfig,
) -> bool {
filter_rule.iter().all(|(k, v)| {
Expand All @@ -109,10 +109,9 @@ impl EventSearch {
)
.unwrap_or_else(|| "n/a".into())
.replace(['"', '\''], "");

// aliasでマッチした場合はaliasに登録されていないフィールドを検索する必要がないためtrueを返す
if v.iter()
.all(|search_target| utils::contains_str(&alias_target_val, search_target))
.all(|search_target| search_target.matches(&alias_target_val))

Check warning on line 114 in src/timeline/search.rs

View check run for this annotation

Codecov / codecov/patch

src/timeline/search.rs#L114

Added line #L114 was not covered by tests
{
return true;
}
Expand All @@ -126,7 +125,7 @@ impl EventSearch {
_ => CompactString::new("-"),
};
v.iter()
.all(|search_target| utils::contains_str(&allfieldinfo, search_target))
.all(|search_target| search_target.matches(&allfieldinfo))

Check warning on line 128 in src/timeline/search.rs

View check run for this annotation

Codecov / codecov/patch

src/timeline/search.rs#L128

Added line #L128 was not covered by tests
})
}

Expand Down Expand Up @@ -238,7 +237,7 @@ impl EventSearch {
}

/// filters からフィルタリング条件を作成する関数
fn create_filter_rule(filters: &[String]) -> HashMap<String, Nested<String>> {
fn create_filter_rule(filters: &[String]) -> HashMap<String, Vec<WildMatch>> {

Check warning on line 240 in src/timeline/search.rs

View check run for this annotation

Codecov / codecov/patch

src/timeline/search.rs#L240

Added line #L240 was not covered by tests
filters
.iter()
.fold(HashMap::new(), |mut acc, filter_condition| {
Expand All @@ -250,10 +249,10 @@ fn create_filter_rule(filters: &[String]) -> HashMap<String, Nested<String>> {
.unwrap_or(prefix_trim_condition);
let condition = trimed_condition.split(':').map(|x| x.trim()).collect_vec();
if condition.len() != 1 {
let acc_val = acc
.entry(condition[0].to_string())
.or_insert(Nested::<String>::new());
acc_val.push(condition[1..].join(":"));
let acc_val = acc.entry(condition[0].to_string()).or_insert(vec![]);
condition[1..]
.iter()
.for_each(|x| acc_val.push(WildMatch::new(x)));

Check warning on line 255 in src/timeline/search.rs

View check run for this annotation

Codecov / codecov/patch

src/timeline/search.rs#L252-L255

Added lines #L252 - L255 were not covered by tests
}
acc
})
Expand Down

0 comments on commit 08ac11e

Please sign in to comment.