mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
handle escaped tag searches and tag:* special case
This commit is contained in:
parent
ad09c89c3c
commit
3a4146560c
1 changed files with 13 additions and 7 deletions
|
@ -97,15 +97,20 @@ impl SqlWriter<'_, '_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_tag(&mut self, text: &str) {
|
fn write_tag(&mut self, text: &str) {
|
||||||
if text == "none" {
|
match text {
|
||||||
|
"none" => {
|
||||||
write!(self.sql, "n.tags = ''").unwrap();
|
write!(self.sql, "n.tags = ''").unwrap();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
"*" | "%" => {
|
||||||
|
write!(self.sql, "true").unwrap();
|
||||||
|
}
|
||||||
|
text => {
|
||||||
let tag = format!("% {} %", text.replace('*', "%"));
|
let tag = format!("% {} %", text.replace('*', "%"));
|
||||||
write!(self.sql, "n.tags like ?").unwrap();
|
write!(self.sql, "n.tags like ? escape '\\'").unwrap();
|
||||||
self.args.push(tag);
|
self.args.push(tag);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn write_rated(&mut self, days: u32, ease: Option<u8>) -> Result<()> {
|
fn write_rated(&mut self, days: u32, ease: Option<u8>) -> Result<()> {
|
||||||
let today_cutoff = self.req.storage.timing_today()?.next_day_at;
|
let today_cutoff = self.req.storage.timing_today()?.next_day_at;
|
||||||
|
@ -486,6 +491,7 @@ mod test {
|
||||||
("(n.tags like ?)".into(), vec!["% o%e %".into()])
|
("(n.tags like ?)".into(), vec!["% o%e %".into()])
|
||||||
);
|
);
|
||||||
assert_eq!(s(ctx, "tag:none"), ("(n.tags = '')".into(), vec![]));
|
assert_eq!(s(ctx, "tag:none"), ("(n.tags = '')".into(), vec![]));
|
||||||
|
assert_eq!(s(ctx, "tag:*"), ("(true)".into(), vec![]));
|
||||||
|
|
||||||
// state
|
// state
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in a new issue