|
2 | 2 |
|
3 | 3 | use crate::auth::AuthCheck;
|
4 | 4 | use diesel::dsl::*;
|
5 |
| -use diesel::sql_types::Array; |
| 5 | +use diesel::sql_types::{Array, Text}; |
6 | 6 | use diesel_full_text_search::*;
|
7 | 7 | use indexmap::IndexMap;
|
8 | 8 | use once_cell::sync::OnceCell;
|
@@ -98,10 +98,9 @@ pub async fn search(app: AppState, req: Parts) -> AppResult<Json<Value>> {
|
98 | 98 | query = query.order(Crate::with_name(q_string).desc());
|
99 | 99 |
|
100 | 100 | if sort == "relevance" {
|
101 |
| - let q = to_tsquery_with_search_config( |
102 |
| - configuration::TsConfigurationByName("english"), |
103 |
| - q_string, |
104 |
| - ); |
| 101 | + let q = sql::<TsQuery>("plainto_tsquery('english', ") |
| 102 | + .bind::<Text, _>(q_string) |
| 103 | + .sql(")"); |
105 | 104 | let rank = ts_rank_cd(crates::textsearchable_index_col, q);
|
106 | 105 | query = query.then_order_by(rank.desc())
|
107 | 106 | }
|
@@ -305,15 +304,13 @@ impl<'a> FilterParams<'a> {
|
305 | 304 | req: &Parts,
|
306 | 305 | conn: &mut PgConnection,
|
307 | 306 | ) -> AppResult<crates::BoxedQuery<'a, diesel::pg::Pg>> {
|
308 |
| - use diesel::sql_types::Text; |
309 | 307 | let mut query = crates::table.into_boxed();
|
310 | 308 |
|
311 | 309 | if let Some(q_string) = self.q_string {
|
312 | 310 | if !q_string.is_empty() {
|
313 |
| - let q = to_tsquery_with_search_config( |
314 |
| - configuration::TsConfigurationByName("english"), |
315 |
| - q_string, |
316 |
| - ); |
| 311 | + let q = sql::<TsQuery>("plainto_tsquery('english', ") |
| 312 | + .bind::<Text, _>(q_string) |
| 313 | + .sql(")"); |
317 | 314 | query = query.filter(
|
318 | 315 | q.matches(crates::textsearchable_index_col)
|
319 | 316 | .or(Crate::loosly_matches_name(q_string)),
|
|
0 commit comments