-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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
dstlled-diffexpanddiff --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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.