Allow partial matches on alias.
This commit is contained in:
parent
a9df230a08
commit
8e1d15bade
@ -526,7 +526,7 @@ impl DBTrans {
|
||||
search.from_item.item_code);
|
||||
|
||||
let (offset, mut query) = parse_offset(search.query);
|
||||
let mut param_no: usize = 6;
|
||||
let mut param_no: usize = 5;
|
||||
let mut extra_order: String = String::new();
|
||||
let mut extra_where: String = String::new();
|
||||
|
||||
@ -554,14 +554,12 @@ impl DBTrans {
|
||||
.replace("%", "")
|
||||
.to_lowercase() + "%";
|
||||
let offset_sql = offset.map(|x| (if x >= 1 { x - 1 } else { x}) as i64).unwrap_or(0);
|
||||
let query_json = serde_json::to_value(query.to_lowercase())?;
|
||||
let query_len = query.len() as i32;
|
||||
let limit = search.limit as i64;
|
||||
let mut params: Vec<&(dyn ToSql + Sync)> = vec!(
|
||||
&query_wildcard,
|
||||
&offset_sql,
|
||||
&query_len,
|
||||
&query_json,
|
||||
&limit
|
||||
);
|
||||
|
||||
@ -609,12 +607,14 @@ impl DBTrans {
|
||||
|
||||
Ok(Arc::new(self.pg_trans()?.query(
|
||||
&format!(
|
||||
"WITH {} SELECT details, aliases FROM relevant_items WHERE \
|
||||
"WITH {} SELECT details FROM relevant_items \
|
||||
WHERE \
|
||||
((lower(details->>'display') LIKE $1) \
|
||||
OR (lower(details ->>'display_less_explicit') LIKE $1) \
|
||||
OR aliases @> $4) {} \
|
||||
OR EXISTS (SELECT 1 FROM jsonb_array_elements(aliases) AS al(alias) WHERE \
|
||||
LOWER(alias#>>'{{}}') LIKE $1)) {} \
|
||||
ORDER BY {} ABS(length(details->>'display')-$3) ASC \
|
||||
LIMIT $5 OFFSET $2", &cte_str, &extra_where, &extra_order),
|
||||
LIMIT $4 OFFSET $2", &cte_str, &extra_where, &extra_order),
|
||||
¶ms
|
||||
).await?.into_iter()
|
||||
.filter_map(|i| serde_json::from_value(i.get("details")).ok())
|
||||
|
Loading…
Reference in New Issue
Block a user