fix * handling in unqualifed text as well

https://forums.ankiweb.net/t/anki-2-1-desktop-searching-with-only-when-limited-to-a-field/3789/4
This commit is contained in:
Damien Elmes 2020-09-29 21:18:19 +10:00
parent 1b265f8024
commit 955c1bafb9

View file

@ -167,7 +167,7 @@ impl SqlWriter<'_> {
fn write_unqualified(&mut self, text: &str) { fn write_unqualified(&mut self, text: &str) {
// implicitly wrap in % // implicitly wrap in %
let text = format!("%{}%", text); let text = format!("%{}%", convert_glob_char(text));
self.args.push(text); self.args.push(text);
write!( write!(
self.sql, self.sql,
@ -595,15 +595,16 @@ mod test {
// unqualified search // unqualified search
assert_eq!( assert_eq!(
s(ctx, "test"), s(ctx, "te*st"),
( (
"((n.sfld like ?1 escape '\\' or n.flds like ?1 escape '\\'))".into(), "((n.sfld like ?1 escape '\\' or n.flds like ?1 escape '\\'))".into(),
vec!["%test%".into()] vec!["%te%st%".into()]
) )
); );
assert_eq!(s(ctx, "te%st").1, vec!["%te%st%".to_string()]); assert_eq!(s(ctx, "te%st").1, vec!["%te%st%".to_string()]);
// user should be able to escape sql wildcards // user should be able to escape sql wildcards
assert_eq!(s(ctx, r#"te\%s\_t"#).1, vec!["%te\\%s\\_t%".to_string()]); assert_eq!(s(ctx, r#"te\%s\_t"#).1, vec!["%te\\%s\\_t%".to_string()]);
assert_eq!(s(ctx, r#"te\*s\_t"#).1, vec!["%te\\*s\\_t%".to_string()]);
// qualified search // qualified search
assert_eq!( assert_eq!(