@@ -118,43 +118,42 @@ pub async fn list_crates(
118118 . left_join ( versions:: table. on ( default_versions:: version_id. eq ( versions:: id) ) )
119119 . select ( selection) ;
120120
121- if let Some ( q_string) = & filter_params. q_string {
122- if !q_string. is_empty ( ) {
123- let q_string = q_string. as_str ( ) ;
124-
125- let sort = sort. unwrap_or ( "relevance" ) ;
126-
127- query = query. order ( Crate :: with_name ( q_string) . desc ( ) ) ;
128-
129- if sort == "relevance" {
130- let q =
131- plainto_tsquery_with_search_config ( TsConfigurationByName ( "english" ) , q_string) ;
132- let rank = ts_rank_cd ( crates:: textsearchable_index_col, q) ;
133- query = query. select ( (
134- ALL_COLUMNS ,
135- Crate :: with_name ( q_string) ,
136- crate_downloads:: downloads,
137- recent_crate_downloads:: downloads. nullable ( ) ,
138- rank,
139- versions:: num. nullable ( ) ,
140- versions:: yanked. nullable ( ) ,
141- default_versions:: num_versions. nullable ( ) ,
142- ) ) ;
143- seek = Some ( Seek :: Relevance ) ;
144- query = query. then_order_by ( rank. desc ( ) )
145- } else {
146- query = query. select ( (
147- ALL_COLUMNS ,
148- Crate :: with_name ( q_string) ,
149- crate_downloads:: downloads,
150- recent_crate_downloads:: downloads. nullable ( ) ,
151- 0_f32 . into_sql :: < Float > ( ) ,
152- versions:: num. nullable ( ) ,
153- versions:: yanked. nullable ( ) ,
154- default_versions:: num_versions. nullable ( ) ,
155- ) ) ;
156- seek = Some ( Seek :: Query ) ;
157- }
121+ if let Some ( q_string) = & filter_params. q_string
122+ && !q_string. is_empty ( )
123+ {
124+ let q_string = q_string. as_str ( ) ;
125+
126+ let sort = sort. unwrap_or ( "relevance" ) ;
127+
128+ query = query. order ( Crate :: with_name ( q_string) . desc ( ) ) ;
129+
130+ if sort == "relevance" {
131+ let q = plainto_tsquery_with_search_config ( TsConfigurationByName ( "english" ) , q_string) ;
132+ let rank = ts_rank_cd ( crates:: textsearchable_index_col, q) ;
133+ query = query. select ( (
134+ ALL_COLUMNS ,
135+ Crate :: with_name ( q_string) ,
136+ crate_downloads:: downloads,
137+ recent_crate_downloads:: downloads. nullable ( ) ,
138+ rank,
139+ versions:: num. nullable ( ) ,
140+ versions:: yanked. nullable ( ) ,
141+ default_versions:: num_versions. nullable ( ) ,
142+ ) ) ;
143+ seek = Some ( Seek :: Relevance ) ;
144+ query = query. then_order_by ( rank. desc ( ) )
145+ } else {
146+ query = query. select ( (
147+ ALL_COLUMNS ,
148+ Crate :: with_name ( q_string) ,
149+ crate_downloads:: downloads,
150+ recent_crate_downloads:: downloads. nullable ( ) ,
151+ 0_f32 . into_sql :: < Float > ( ) ,
152+ versions:: num. nullable ( ) ,
153+ versions:: yanked. nullable ( ) ,
154+ default_versions:: num_versions. nullable ( ) ,
155+ ) ) ;
156+ seek = Some ( Seek :: Query ) ;
158157 }
159158 }
160159
@@ -384,17 +383,17 @@ impl FilterParams {
384383 fn make_query ( & self ) -> crates:: BoxedQuery < ' _ , diesel:: pg:: Pg > {
385384 let mut query = crates:: table. into_boxed ( ) ;
386385
387- if let Some ( q_string) = & self . q_string {
388- if !q_string. is_empty ( ) {
389- let q = plainto_tsquery_with_search_config (
390- TsConfigurationByName ( "english" ) ,
391- q_string . as_str ( ) ,
392- ) ;
393- query = query . filter (
394- q . matches ( crates :: textsearchable_index_col )
395- . or ( Crate :: loosly_matches_name ( q_string . as_str ( ) ) ) ,
396- ) ;
397- }
386+ if let Some ( q_string) = & self . q_string
387+ && !q_string. is_empty ( )
388+ {
389+ let q = plainto_tsquery_with_search_config (
390+ TsConfigurationByName ( "english" ) ,
391+ q_string . as_str ( ) ,
392+ ) ;
393+ query = query . filter (
394+ q . matches ( crates :: textsearchable_index_col )
395+ . or ( Crate :: loosly_matches_name ( q_string . as_str ( ) ) ) ,
396+ ) ;
398397 }
399398
400399 if let Some ( cat) = & self . category {
0 commit comments