mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
add separate search_notes_only()
This commit is contained in:
parent
04f0ea8599
commit
7c23deb562
1 changed files with 22 additions and 5 deletions
|
@ -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<Vec<NoteID>> {
|
||||
/// This supports card queries as well, but is slower.
|
||||
pub fn search_notes(&mut self, search: &str) -> Result<Vec<NoteID>> {
|
||||
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<Vec<NoteID>> {
|
||||
self.search_notes_inner(search, |sql| {
|
||||
format!("select n.id from notes n where {}", sql)
|
||||
})
|
||||
}
|
||||
|
||||
fn search_notes_inner<F>(&mut self, search: &str, build_sql: F) -> Result<Vec<NoteID>>
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue