@@ -132,7 +132,6 @@ pub(crate) async fn get_releases(
132
132
133
133
struct SearchResult {
134
134
pub results : Vec < Release > ,
135
- pub executed_query : Option < String > ,
136
135
pub prev_page : Option < String > ,
137
136
pub next_page : Option < String > ,
138
137
}
@@ -145,11 +144,7 @@ async fn get_search_results(
145
144
registry : & RegistryApi ,
146
145
query_params : & str ,
147
146
) -> Result < SearchResult , anyhow:: Error > {
148
- let crate :: registry_api:: Search {
149
- crates,
150
- meta,
151
- executed_query,
152
- } = registry. search ( query_params) . await ?;
147
+ let crate :: registry_api:: Search { crates, meta } = registry. search ( query_params) . await ?;
153
148
154
149
let names = Arc :: new (
155
150
crates
@@ -220,7 +215,6 @@ async fn get_search_results(
220
215
. filter_map ( |name| crates. get ( name) )
221
216
. cloned ( )
222
217
. collect ( ) ,
223
- executed_query,
224
218
prev_page : meta. prev_page ,
225
219
next_page : meta. next_page ,
226
220
} )
@@ -506,7 +500,7 @@ pub(crate) async fn search_handler(
506
500
Extension ( metrics) : Extension < Arc < InstanceMetrics > > ,
507
501
Query ( mut params) : Query < HashMap < String , String > > ,
508
502
) -> AxumResult < AxumResponse > {
509
- let query = params
503
+ let mut query = params
510
504
. get ( "query" )
511
505
. map ( |q| q. to_string ( ) )
512
506
. unwrap_or_else ( || "" . to_string ( ) ) ;
@@ -568,39 +562,28 @@ pub(crate) async fn search_handler(
568
562
569
563
let search_result = if let Some ( paginate) = params. get ( "paginate" ) {
570
564
let decoded = b64. decode ( paginate. as_bytes ( ) ) . map_err ( |e| {
571
- warn ! (
572
- "error when decoding pagination base64 string \" {}\" : {:?}" ,
573
- paginate, e
574
- ) ;
565
+ warn ! ( "error when decoding pagination base64 string \" {paginate}\" : {e:?}" ) ;
575
566
AxumNope :: NoResults
576
567
} ) ?;
577
568
let query_params = String :: from_utf8_lossy ( & decoded) ;
578
- let query_params = match query_params. strip_prefix ( '?' ) {
579
- Some ( query_params) => query_params,
580
- None => {
581
- // sometimes we see plain bytes being passed to `paginate`.
582
- // In these cases we just return `NoResults` and don't call
583
- // the crates.io API.
584
- // The whole point of the `paginate` design is that we don't
585
- // know anything about the pagination args and crates.io can
586
- // change them as they wish, so we cannot do any more checks here.
587
- warn ! (
588
- "didn't get query args in `paginate` arguments for search: \" {query_params}\" "
589
- ) ;
590
- return Err ( AxumNope :: NoResults ) ;
591
- }
592
- } ;
569
+ let query_params = query_params. strip_prefix ( '?' ) . ok_or_else ( || {
570
+ // sometimes we see plain bytes being passed to `paginate`.
571
+ // In these cases we just return `NoResults` and don't call
572
+ // the crates.io API.
573
+ // The whole point of the `paginate` design is that we don't
574
+ // know anything about the pagination args and crates.io can
575
+ // change them as they wish, so we cannot do any more checks here.
576
+ warn ! ( "didn't get query args in `paginate` arguments for search: \" {query_params}\" " ) ;
577
+ AxumNope :: NoResults
578
+ } ) ?;
593
579
594
- let mut p = form_urlencoded:: parse ( query_params. as_bytes ( ) ) ;
595
- if let Some ( v) = p. find_map ( |( k, v) | {
596
- if & k == "sort" {
597
- Some ( v. to_string ( ) )
598
- } else {
599
- None
580
+ for ( k, v) in form_urlencoded:: parse ( query_params. as_bytes ( ) ) {
581
+ match & * k {
582
+ "q" => query = v. to_string ( ) ,
583
+ "sort" => sort_by = v. to_string ( ) ,
584
+ _ => { }
600
585
}
601
- } ) {
602
- sort_by = v;
603
- } ;
586
+ }
604
587
605
588
get_search_results ( & mut conn, & registry, query_params) . await ?
606
589
} else if !query. is_empty ( ) {
@@ -615,18 +598,16 @@ pub(crate) async fn search_handler(
615
598
return Err ( AxumNope :: NoResults ) ;
616
599
} ;
617
600
618
- let executed_query = search_result. executed_query . unwrap_or_default ( ) ;
619
-
620
601
let title = if search_result. results . is_empty ( ) {
621
- format ! ( "No results found for '{executed_query }'" )
602
+ format ! ( "No results found for '{query }'" )
622
603
} else {
623
- format ! ( "Search results for '{executed_query }'" )
604
+ format ! ( "Search results for '{query }'" )
624
605
} ;
625
606
626
607
Ok ( Search {
627
608
title,
628
609
releases : search_result. results ,
629
- search_query : Some ( executed_query ) ,
610
+ search_query : Some ( query ) ,
630
611
search_sort_by : Some ( sort_by) ,
631
612
next_page_link : search_result
632
613
. next_page
0 commit comments