Skip to content

Commit

Permalink
spi-search:fix q.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Dec 21, 2023
1 parent e8f97a0 commit 99f4285
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions spi/spi-search/src/serv/pg/search_pg_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,19 @@ pub async fn search(search_req: &mut SearchItemSearchReq, funs: &TardisFunsInst,
match search_req.query.q_scope.as_ref().unwrap_or(&SearchItemSearchQScopeKind::Title) {
SearchItemSearchQScopeKind::Title => {
select_fragments = ", COALESCE(ts_rank(title_tsv, query), 0::float4) AS rank_title, 0::float4 AS rank_content".to_string();
where_fragments.push(format!("(query @@ title_tsv OR {} LIKE ${})", ext_item.field, sql_vals.len()));
where_fragments.push(format!("(query @@ title_tsv OR title LIKE ${})", sql_vals.len()));
}
SearchItemSearchQScopeKind::Content => {
select_fragments = ", 0::float4 AS rank_title, COALESCE(ts_rank(content_tsv, query), 0::float4) AS rank_content".to_string();
where_fragments.push(format!("(query @@ content_tsv OR {} LIKE ${})", ext_item.field, sql_vals.len()));
where_fragments.push(format!("(query @@ content_tsv OR content LIKE ${})", sql_vals.len()));
}
SearchItemSearchQScopeKind::TitleContent => {
select_fragments = ", COALESCE(ts_rank(title_tsv, query), 0::float4) AS rank_title, COALESCE(ts_rank(content_tsv, query), 0::float4) AS rank_content".to_string();
where_fragments.push(format!("(query @@ title_tsv OR query @@ content_tsv OR {} LIKE ${})", ext_item.field, sql_vals.len()));
where_fragments.push(format!(
"(query @@ title_tsv OR query @@ content_tsv OR title LIKE ${} OR content LIKE ${})",
sql_vals.len(),
sql_vals.len()
));
}
}
} else {
Expand Down

0 comments on commit 99f4285

Please sign in to comment.