Skip to content

Commit

Permalink
spi-search:fix query own_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Jan 31, 2024
1 parent b06d946 commit b127698
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions spi/spi-search/src/dto/search_item_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub struct SearchItemQueryReq {
pub owners: Option<Vec<String>>,
// Match own_path, support prefix match
pub own_paths: Option<Vec<String>>,
pub rlike_own_paths: Option<Vec<String>>,
pub create_time_start: Option<DateTime<Utc>>,
pub create_time_end: Option<DateTime<Utc>>,
pub update_time_start: Option<DateTime<Utc>>,
Expand Down
34 changes: 28 additions & 6 deletions spi/spi-search/src/serv/pg/search_pg_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ pub async fn search(search_req: &mut SearchItemSearchReq, funs: &TardisFunsInst,
}
}
if let Some(own_paths) = &search_req.query.own_paths {
if !own_paths.is_empty() {
where_fragments.push(format!(
"own_paths in ({})",
(0..own_paths.len()).map(|idx| format!("${}", sql_vals.len() + idx + 1)).collect::<Vec<String>>().join(",")
));
for own_path in own_paths {
sql_vals.push(Value::from(format!("{own_path}%")));
}
}
}
if let Some(own_paths) = &search_req.query.rlike_own_paths {
if !own_paths.is_empty() {
where_fragments.push(format!(
"own_paths LIKE ANY (ARRAY[{}])",
Expand Down Expand Up @@ -920,12 +931,23 @@ pub async fn query_metrics(query_req: &SearchQueryMetricsReq, funs: &TardisFunsI
}
if let Some(own_paths) = &query_req.query.own_paths {
if !own_paths.is_empty() {
sql_part_wheres.push(format!(
"fact.own_paths LIKE ANY (ARRAY[{}])",
(0..own_paths.len()).map(|idx| format!("${}", params.len() + idx + 1)).collect::<Vec<String>>().join(",")
where_fragments.push(format!(
"own_paths in ({})",
(0..own_paths.len()).map(|idx| format!("${}", sql_vals.len() + idx + 1)).collect::<Vec<String>>().join(",")
));
for own_path in own_paths {
params.push(Value::from(format!("{own_path}%")));
sql_vals.push(Value::from(format!("{own_path}%")));
}
}
}
if let Some(own_paths) = &query_req.query.rlike_own_paths {
if !own_paths.is_empty() {
where_fragments.push(format!(
"own_paths LIKE ANY (ARRAY[{}])",
(0..own_paths.len()).map(|idx| format!("${}", sql_vals.len() + idx + 1)).collect::<Vec<String>>().join(",")
));
for own_path in own_paths {
sql_vals.push(Value::from(format!("{own_path}%")));
}
}
}
Expand Down Expand Up @@ -1215,8 +1237,8 @@ pub async fn query_metrics(query_req: &SearchQueryMetricsReq, funs: &TardisFunsI
sql_adv_query.push(format!(
" {} ( {} )",
if group_query.group_by_or.unwrap_or(false) { "OR" } else { "AND" },
sql_and_where.join(if group_query.ext_by_or.unwrap_or(false) { " OR " } else { " AND " }))
);
sql_and_where.join(if group_query.ext_by_or.unwrap_or(false) { " OR " } else { " AND " })
));
}
}
}
Expand Down

0 comments on commit b127698

Please sign in to comment.