@@ -6,11 +6,11 @@ use axum_extra::extract::Query;
6
6
use axum_extra:: json;
7
7
use axum_extra:: response:: ErasedJson ;
8
8
use derive_more:: Deref ;
9
- use diesel:: dsl:: { exists, sql , InnerJoinQuerySource , LeftJoinQuerySource } ;
9
+ use diesel:: dsl:: { exists, InnerJoinQuerySource , LeftJoinQuerySource } ;
10
10
use diesel:: prelude:: * ;
11
- use diesel:: sql_types:: { Bool , Text } ;
11
+ use diesel:: sql_types:: Bool ;
12
12
use diesel_async:: { AsyncPgConnection , RunQueryDsl } ;
13
- use diesel_full_text_search:: * ;
13
+ use diesel_full_text_search:: { configuration :: TsConfigurationByName , * } ;
14
14
use http:: request:: Parts ;
15
15
use tracing:: Instrument ;
16
16
use utoipa:: IntoParams ;
@@ -102,16 +102,15 @@ pub async fn list_crates(
102
102
query = query. order ( Crate :: with_name ( q_string) . desc ( ) ) ;
103
103
104
104
if sort == "relevance" {
105
- let q = sql :: < TsQuery > ( "plainto_tsquery('english', " )
106
- . bind :: < Text , _ > ( q_string)
107
- . sql ( ")" ) ;
105
+ let q =
106
+ plainto_tsquery_with_search_config ( TsConfigurationByName ( "english" ) , q_string) ;
108
107
let rank = ts_rank_cd ( crates:: textsearchable_index_col, q) ;
109
108
query = query. select ( (
110
109
ALL_COLUMNS ,
111
110
Crate :: with_name ( q_string) ,
112
111
crate_downloads:: downloads,
113
112
recent_crate_downloads:: downloads. nullable ( ) ,
114
- rank. clone ( ) ,
113
+ rank,
115
114
versions:: num. nullable ( ) ,
116
115
versions:: yanked. nullable ( ) ,
117
116
) ) ;
@@ -359,9 +358,10 @@ impl FilterParams {
359
358
360
359
if let Some ( q_string) = & self . q_string {
361
360
if !q_string. is_empty ( ) {
362
- let q = sql :: < TsQuery > ( "plainto_tsquery('english', " )
363
- . bind :: < Text , _ > ( q_string. as_str ( ) )
364
- . sql ( ")" ) ;
361
+ let q = plainto_tsquery_with_search_config (
362
+ TsConfigurationByName ( "english" ) ,
363
+ q_string. as_str ( ) ,
364
+ ) ;
365
365
query = query. filter (
366
366
q. matches ( crates:: textsearchable_index_col)
367
367
. or ( Crate :: loosly_matches_name ( q_string. as_str ( ) ) ) ,
@@ -590,16 +590,17 @@ impl FilterParams {
590
590
// ORDER BY exact_match DESC, rank DESC, name ASC
591
591
// ```
592
592
let q_string = self . q_string . as_ref ( ) . expect ( "q_string should not be None" ) ;
593
- let q = sql :: < TsQuery > ( "plainto_tsquery('english', " )
594
- . bind :: < Text , _ > ( q_string. as_str ( ) )
595
- . sql ( ")" ) ;
593
+ let q = plainto_tsquery_with_search_config (
594
+ TsConfigurationByName ( "english" ) ,
595
+ q_string. as_str ( ) ,
596
+ ) ;
596
597
let rank = ts_rank_cd ( crates:: textsearchable_index_col, q) ;
597
598
let name_exact_match = Crate :: with_name ( q_string. as_str ( ) ) ;
598
599
vec ! [
599
600
Box :: new(
600
601
name_exact_match
601
602
. eq( exact)
602
- . and( rank. clone ( ) . eq( rank_in) )
603
+ . and( rank. eq( rank_in) )
603
604
. and( crates:: name. nullable( ) . gt( crate_name_by_id( id) ) )
604
605
. nullable( ) ,
605
606
) ,
0 commit comments