mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 00:12:25 -04:00
fix qualified search
This commit is contained in:
parent
c723adea17
commit
5df04b161c
1 changed files with 29 additions and 10 deletions
|
@ -269,23 +269,28 @@ impl SqlWriter<'_, '_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for now, sort the map for the benefit of unit tests
|
||||||
|
field_map.sort();
|
||||||
|
|
||||||
if field_map.is_empty() {
|
if field_map.is_empty() {
|
||||||
write!(self.sql, "false").unwrap();
|
write!(self.sql, "false").unwrap();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(self.sql, "(").unwrap();
|
|
||||||
self.args.push(val.to_string().into());
|
self.args.push(val.to_string().into());
|
||||||
let arg_idx = self.args.len();
|
let arg_idx = self.args.len();
|
||||||
for (ntid, ord) in field_map {
|
let searches: Vec<_> = field_map
|
||||||
write!(
|
.iter()
|
||||||
self.sql,
|
.map(|(ntid, ord)| {
|
||||||
"(n.mid = {} and field_at_index(n.flds, {}) like ?{})",
|
format!(
|
||||||
ntid, ord, arg_idx
|
"(n.mid = {mid} and field_at_index(n.flds, {ord}) like ?{n})",
|
||||||
)
|
mid = ntid,
|
||||||
.unwrap();
|
ord = ord,
|
||||||
}
|
n = arg_idx
|
||||||
write!(self.sql, ")").unwrap();
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
write!(self.sql, "({})", searches.join(" or ")).unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -383,6 +388,20 @@ mod test {
|
||||||
// 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()]);
|
||||||
|
|
||||||
|
// qualified search
|
||||||
|
assert_eq!(
|
||||||
|
s(ctx, "front:test"),
|
||||||
|
(
|
||||||
|
concat!(
|
||||||
|
"(((n.mid = 1581236385344 and field_at_index(n.flds, 0) like ?1) or ",
|
||||||
|
"(n.mid = 1581236385345 and field_at_index(n.flds, 0) like ?1) or ",
|
||||||
|
"(n.mid = 1581236385346 and field_at_index(n.flds, 0) like ?1) or ",
|
||||||
|
"(n.mid = 1581236385347 and field_at_index(n.flds, 0) like ?1)))"
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
vec!["test".into()]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue