Skip to content

Commit

Permalink
fix: improve SQL query formatting and add length check for ext items …
Browse files Browse the repository at this point in the history
…in search_pg_item_serv.rs
  • Loading branch information
RWDai committed Dec 30, 2024
1 parent ad484a8 commit 60e30a7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion backend/spi/spi-search/src/serv/pg/search_pg_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ WHERE
if sql_adv_query.is_empty() {
"".to_string()
} else {
format!(" {} ( 1=1 {})", if search_req.adv_by_or.unwrap_or(false) { " OR " } else { " AND " }, sql_adv_query.join(" "))
format!(
" {} ( 1=1 {})",
if search_req.adv_by_or.unwrap_or(false) { " OR " } else { " AND " },
sql_adv_query.join(" ")
)
},
if order_fragments.is_empty() {
"".to_string()
Expand Down Expand Up @@ -694,6 +698,13 @@ fn package_ext(
"({}.ext ->> '{}' is null or {}.ext ->> '{}' = '' or {}.ext ->> '{}' = '[]')",
table_alias_name, ext_item.field, table_alias_name, ext_item.field, table_alias_name, ext_item.field
));
} else if ext_item.op == BasicQueryOpKind::Len {
if let Some(first_value) = value.pop() {
where_fragments.push(format!("(length(ext->>'{}') = ${})", ext_item.field, sql_vals.len() + 1));
sql_vals.push(first_value);
} else {
return err_not_found(ext_item);
};
} else {
if value.len() > 1 {
return err_not_found(&ext_item.clone().into());
Expand Down

0 comments on commit 60e30a7

Please sign in to comment.