@@ -418,6 +418,7 @@ pub(super) struct Search {
418418 #[ serde( rename = "releases" ) ]
419419 pub ( super ) results : Vec < Release > ,
420420 pub ( super ) search_query : Option < String > ,
421+ pub ( super ) search_sort_by : Option < String > ,
421422 pub ( super ) previous_page_link : Option < String > ,
422423 pub ( super ) next_page_link : Option < String > ,
423424 /// This should always be `ReleaseType::Search`
@@ -434,6 +435,7 @@ impl Default for Search {
434435 search_query : None ,
435436 previous_page_link : None ,
436437 next_page_link : None ,
438+ search_sort_by : None ,
437439 release_type : ReleaseType :: Search ,
438440 status : http:: StatusCode :: OK ,
439441 }
@@ -507,7 +509,10 @@ pub(crate) async fn search_handler(
507509 . get ( "query" )
508510 . map ( |q| q. to_string ( ) )
509511 . unwrap_or_else ( || "" . to_string ( ) ) ;
510-
512+ let sort_by = params
513+ . get ( "sort" )
514+ . map ( |q| q. to_string ( ) )
515+ . unwrap_or_else ( || "relevance" . to_string ( ) ) ;
511516 // check if I am feeling lucky button pressed and redirect user to crate page
512517 // if there is a match. Also check for paths to items within crates.
513518 if params. remove ( "i-am-feeling-lucky" ) . is_some ( ) || query. contains ( "::" ) {
@@ -578,6 +583,7 @@ pub(crate) async fn search_handler(
578583 } else if !query. is_empty ( ) {
579584 let query_params: String = form_urlencoded:: Serializer :: new ( String :: new ( ) )
580585 . append_pair ( "q" , & query)
586+ . append_pair ( "sort" , & sort_by)
581587 . append_pair ( "per_page" , & RELEASES_IN_RELEASES . to_string ( ) )
582588 . finish ( ) ;
583589
@@ -598,6 +604,7 @@ pub(crate) async fn search_handler(
598604 title,
599605 results : search_result. results ,
600606 search_query : Some ( executed_query) ,
607+ search_sort_by : Some ( sort_by) ,
601608 next_page_link : search_result
602609 . next_page
603610 . map ( |params| format ! ( "/releases/search?paginate={}" , b64. encode( params) ) ) ,
0 commit comments