Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow searching over multiple terms #5

Merged
merged 13 commits into from
Feb 21, 2025

Conversation

dhth
Copy link
Owner

@dhth dhth commented Feb 21, 2025

No description provided.

Copy link

github-actions bot commented Feb 21, 2025

dstlled-diff

218f4b7..598c710 -- **.rs

expand
diff --git a/218f4b73/src/args.rs b/598c7103/src/args.rs
index 0aa6350..c4f1a41 100644
--- a/218f4b73/src/args.rs
+++ b/598c7103/src/args.rs
@@ -113 +113 @@ pub enum BmmCommand {
-    /// Search bookmarks based on a singular query
+    /// Search bookmarks by matching over terms
@@ -115,3 +115,3 @@ pub enum BmmCommand {
-        /// Pattern to match any attribute of a bookmark (URI, title, tags)
-        #[arg(value_name = "QUERY")]
-        query: String,
+        /// Query terms to search bookmarks with (will be matched over bookmark uri, title, and tags)
+        #[arg(value_name = "TERM")]
+        query_terms: Vec<String>,
diff --git a/218f4b73/src/cli/list.rs b/598c7103/src/cli/list.rs
index e655b41..3b2d7ca 100644
--- a/218f4b73/src/cli/list.rs
+++ b/598c7103/src/cli/list.rs
@@ -6,2 +5,0 @@ pub enum ListBookmarksError {
-    #[error(transparent)]
-    CouldntRunTui(#[from] AppTuiError),
@@ -17,7 +14,0 @@ pub fn list_bookmarks(
-pub fn search_bookmarks(
-    pool: &Pool<Sqlite>,
-    query: &str,
-    format: OutputFormat,
-    limit: u16,
-    tui: bool,
-) -> Result<(), ListBookmarksError>
diff --git a/598c7103/src/cli/search.rs b/598c7103/src/cli/search.rs
new file mode 100644
index 0000000..8a7e00c
--- /dev/null
+++ b/598c7103/src/cli/search.rs
@@ -0,0 +1,17 @@
+pub enum SearchBookmarksError {
+    #[error("search query is invalid: {0}")]
+    SearchQueryInvalid(#[from] SearchTermsError),
+    #[error("couldn't get bookmarks from db: {0}")]
+    CouldntGetBookmarksFromDB(DBError),
+    #[error("couldn't display results: {0}")]
+    CouldntDisplayResults(DisplayError),
+    #[error(transparent)]
+    CouldntRunTui(#[from] AppTuiError),
+}
+pub fn search_bookmarks(
+    pool: &Pool<Sqlite>,
+    query_terms: &Vec<String>,
+    format: OutputFormat,
+    limit: u16,
+    tui: bool,
+) -> Result<(), SearchBookmarksError>
diff --git a/218f4b73/src/errors.rs b/598c7103/src/errors.rs
index 529a9f9..dfa0200 100644
--- a/218f4b73/src/errors.rs
+++ b/598c7103/src/errors.rs
@@ -17 +17,3 @@ pub enum AppError {
-    #[error("couldn't save bookmark: {0}")]
+    #[error("couldn't search bookmarks: {0}")]
+    CouldntSearchBookmarks(#[from] SearchBookmarksError),
+    #[error("couldn't search bookmarks: {0}")]
diff --git a/218f4b73/src/persistence/get.rs b/598c7103/src/persistence/get.rs
index e169150..35bb5a3 100644
--- a/218f4b73/src/persistence/get.rs
+++ b/598c7103/src/persistence/get.rs
@@ -0,0 +1,12 @@
+pub enum SearchTermsError {
+    #[error("query is empty")]
+    QueryEmpty,
+    #[error("too many terms (maximum allowed: {SEARCH_TERMS_UPPER_LIMIT})")]
+    TooManyTerms,
+}
+pub struct SearchTerms(Vec<String>);
+type Error = SearchTermsError;
+type Error = SearchTermsError;
+pub fn iter(&self) -> std::slice::Iter<String>
+fn try_from(value: &str) -> Result<Self, Self::Error>
+fn try_from(value: &Vec<String>) -> Result<Self, Self::Error>
@@ -18 +30 @@ pub fn get_bookmarks_by_query(
-    search_query: &str,
+    search_terms: &SearchTerms,
diff --git a/218f4b73/src/tui/commands.rs b/598c7103/src/tui/commands.rs
index 8cca3cc..8c8bf57 100644
--- a/218f4b73/src/tui/commands.rs
+++ b/598c7103/src/tui/commands.rs
@@ -3 +3 @@ pub(super) enum Command {
-    SearchBookmarks(String),
+    SearchBookmarks(SearchTerms),
diff --git a/218f4b73/src/tui/model.rs b/598c7103/src/tui/model.rs
index 800f6ef..f7d7a2f 100644
--- a/218f4b73/src/tui/model.rs
+++ b/598c7103/src/tui/model.rs
@@ -24 +24 @@ pub enum TuiContext {
-    Search(String),
+    Search(SearchTerms),
diff --git a/218f4b73/tests/search_test.rs b/598c7103/tests/search_test.rs
index f8022b0..d24eb1b 100644
--- a/218f4b73/tests/search_test.rs
+++ b/598c7103/tests/search_test.rs
@@ -3,0 +4,3 @@ fn searching_bookmarks_by_tags_works()
+fn searching_bookmarks_by_multiple_terms_works()
+fn searching_bookmarks_fails_if_search_terms_exceeds_limit()
+fn searching_bookmarks_fails_if_search_query_empty()

@dhth dhth added the bench To benchmark against main label Feb 21, 2025
@dhth dhth removed the bench To benchmark against main label Feb 21, 2025
@dhth dhth added bench To benchmark against main and removed bench To benchmark against main labels Feb 21, 2025
@dhth dhth added the bench To benchmark against main label Feb 21, 2025
@dhth dhth merged commit ca29c8c into main Feb 21, 2025
@dhth dhth deleted the allow-searching-over-multiple-keywords branch February 21, 2025 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bench To benchmark against main
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant