@@ -132,7 +132,6 @@ pub(crate) async fn get_releases(
132132
133133struct SearchResult {
134134 pub results : Vec < Release > ,
135- pub executed_query : Option < String > ,
136135 pub prev_page : Option < String > ,
137136 pub next_page : Option < String > ,
138137}
@@ -145,11 +144,7 @@ async fn get_search_results(
145144 registry : & RegistryApi ,
146145 query_params : & str ,
147146) -> 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 ?;
153148
154149 let names = Arc :: new (
155150 crates
@@ -220,7 +215,6 @@ async fn get_search_results(
220215 . filter_map ( |name| crates. get ( name) )
221216 . cloned ( )
222217 . collect ( ) ,
223- executed_query,
224218 prev_page : meta. prev_page ,
225219 next_page : meta. next_page ,
226220 } )
@@ -506,7 +500,7 @@ pub(crate) async fn search_handler(
506500 Extension ( metrics) : Extension < Arc < InstanceMetrics > > ,
507501 Query ( mut params) : Query < HashMap < String , String > > ,
508502) -> AxumResult < AxumResponse > {
509- let query = params
503+ let mut query = params
510504 . get ( "query" )
511505 . map ( |q| q. to_string ( ) )
512506 . unwrap_or_else ( || "" . to_string ( ) ) ;
@@ -568,39 +562,28 @@ pub(crate) async fn search_handler(
568562
569563 let search_result = if let Some ( paginate) = params. get ( "paginate" ) {
570564 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:?}" ) ;
575566 AxumNope :: NoResults
576567 } ) ?;
577568 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+ } ) ?;
593579
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+ _ => { }
600585 }
601- } ) {
602- sort_by = v;
603- } ;
586+ }
604587
605588 get_search_results ( & mut conn, & registry, query_params) . await ?
606589 } else if !query. is_empty ( ) {
@@ -615,18 +598,16 @@ pub(crate) async fn search_handler(
615598 return Err ( AxumNope :: NoResults ) ;
616599 } ;
617600
618- let executed_query = search_result. executed_query . unwrap_or_default ( ) ;
619-
620601 let title = if search_result. results . is_empty ( ) {
621- format ! ( "No results found for '{executed_query }'" )
602+ format ! ( "No results found for '{query }'" )
622603 } else {
623- format ! ( "Search results for '{executed_query }'" )
604+ format ! ( "Search results for '{query }'" )
624605 } ;
625606
626607 Ok ( Search {
627608 title,
628609 releases : search_result. results ,
629- search_query : Some ( executed_query ) ,
610+ search_query : Some ( query ) ,
630611 search_sort_by : Some ( sort_by) ,
631612 next_page_link : search_result
632613 . next_page
0 commit comments