diff --git a/rslib/src/search/notes.rs b/rslib/src/search/notes.rs index 8dda0fb62..286848f65 100644 --- a/rslib/src/search/notes.rs +++ b/rslib/src/search/notes.rs @@ -8,14 +8,31 @@ use crate::notes::NoteID; use crate::search::parser::parse; impl Collection { - pub(crate) fn search_notes(&mut self, search: &str) -> Result> { + /// This supports card queries as well, but is slower. + pub fn search_notes(&mut self, search: &str) -> Result> { + self.search_notes_inner(search, |sql| { + format!( + "select distinct n.id from cards c, notes n where c.nid=n.id and {}", + sql + ) + }) + } + + /// This only supports note-related search terms. + pub fn search_notes_only(&mut self, search: &str) -> Result> { + self.search_notes_inner(search, |sql| { + format!("select n.id from notes n where {}", sql) + }) + } + + fn search_notes_inner(&mut self, search: &str, build_sql: F) -> Result> + where + F: FnOnce(String) -> String, + { let top_node = Node::Group(parse(search)?); let (sql, args) = node_to_sql(self, &top_node)?; - let sql = format!( - "select n.id from cards c, notes n where c.nid=n.id and {}", - sql - ); + let sql = build_sql(sql); let mut stmt = self.storage.db.prepare(&sql)?; let ids: Vec<_> = stmt