From 49f5d2cd7393cec5f429ebe387232220499176ca Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Sat, 30 Dec 2023 18:51:17 +0800 Subject: [PATCH] feat: change fulltext to exact search mode --- atuin-client/config.toml | 2 +- atuin-client/src/database.rs | 15 ++++++++++----- atuin-client/src/settings.rs | 13 ++++++------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/atuin-client/config.toml b/atuin-client/config.toml index 9a094f8811b..45bb2ba649e 100644 --- a/atuin-client/config.toml +++ b/atuin-client/config.toml @@ -31,7 +31,7 @@ # sync_frequency = "10m" ## which search mode to use -## possible values: prefix, fulltext, fuzzy, skim +## possible values: prefix, exact, fuzzy, skim # search_mode = "fuzzy" ## which filter mode to use diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index 19fccb0c0ff..9add4ec3132 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -427,7 +427,6 @@ impl Database for Sqlite { match search_mode { SearchMode::Prefix => sql.and_where_like_left("command", query), - SearchMode::FullText => sql.and_where_like_any("command", query), _ => { // don't recompile the regex on successive calls! lazy_static! { @@ -448,6 +447,7 @@ impl Database for Sqlite { None => (false, query_part), }; + #[allow(clippy::if_same_then_else)] let param = if query_part == "|" { if !is_or { is_or = true; @@ -463,6 +463,8 @@ impl Database for Sqlite { format!("{glob}{term}{glob}") } else if is_inverse { format!("{glob}{query_part}{glob}") + } else if search_mode == SearchMode::Exact { + format!("{glob}{query_part}{glob}") } else { query_part.split("").join(glob) }; @@ -802,17 +804,20 @@ mod test { } #[tokio::test(flavor = "multi_thread")] - async fn test_search_fulltext() { + async fn test_search_exact() { let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap(); new_history_item(&mut db, "ls /home/ellie").await.unwrap(); - assert_search_eq(&db, SearchMode::FullText, FilterMode::Global, "ls", 1) + assert_search_eq(&db, SearchMode::Exact, FilterMode::Global, "ls", 1) + .await + .unwrap(); + assert_search_eq(&db, SearchMode::Exact, FilterMode::Global, "/home", 1) .await .unwrap(); - assert_search_eq(&db, SearchMode::FullText, FilterMode::Global, "/home", 1) + assert_search_eq(&db, SearchMode::Exact, FilterMode::Global, "ls ho", 1) .await .unwrap(); - assert_search_eq(&db, SearchMode::FullText, FilterMode::Global, "ls ", 0) + assert_search_eq(&db, SearchMode::Exact, FilterMode::Global, "hm", 0) .await .unwrap(); } diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs index de6b10a42c0..d1cf9da39f4 100644 --- a/atuin-client/src/settings.rs +++ b/atuin-client/src/settings.rs @@ -32,9 +32,8 @@ pub enum SearchMode { #[serde(rename = "prefix")] Prefix, - #[serde(rename = "fulltext")] - #[clap(aliases = &["fulltext"])] - FullText, + #[serde(rename = "exact")] + Exact, #[serde(rename = "fuzzy")] Fuzzy, @@ -47,18 +46,18 @@ impl SearchMode { pub fn as_str(&self) -> &'static str { match self { SearchMode::Prefix => "PREFIX", - SearchMode::FullText => "FULLTXT", + SearchMode::Exact => "EXACT", SearchMode::Fuzzy => "FUZZY", SearchMode::Skim => "SKIM", } } pub fn next(&self, settings: &Settings) -> Self { match self { - SearchMode::Prefix => SearchMode::FullText, + SearchMode::Prefix => SearchMode::Exact, // if the user is using skim, we go to skim - SearchMode::FullText if settings.search_mode == SearchMode::Skim => SearchMode::Skim, + SearchMode::Exact if settings.search_mode == SearchMode::Skim => SearchMode::Skim, // otherwise fuzzy. - SearchMode::FullText => SearchMode::Fuzzy, + SearchMode::Exact => SearchMode::Fuzzy, SearchMode::Fuzzy | SearchMode::Skim => SearchMode::Prefix, } }