@@ -418,6 +418,7 @@ pub(super) struct Search {
418
418
#[ serde( rename = "releases" ) ]
419
419
pub ( super ) results : Vec < Release > ,
420
420
pub ( super ) search_query : Option < String > ,
421
+ pub ( super ) search_sort_by : Option < String > ,
421
422
pub ( super ) previous_page_link : Option < String > ,
422
423
pub ( super ) next_page_link : Option < String > ,
423
424
/// This should always be `ReleaseType::Search`
@@ -434,6 +435,7 @@ impl Default for Search {
434
435
search_query : None ,
435
436
previous_page_link : None ,
436
437
next_page_link : None ,
438
+ search_sort_by : None ,
437
439
release_type : ReleaseType :: Search ,
438
440
status : http:: StatusCode :: OK ,
439
441
}
@@ -507,7 +509,10 @@ pub(crate) async fn search_handler(
507
509
. get ( "query" )
508
510
. map ( |q| q. to_string ( ) )
509
511
. 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 ( ) ) ;
511
516
// check if I am feeling lucky button pressed and redirect user to crate page
512
517
// if there is a match. Also check for paths to items within crates.
513
518
if params. remove ( "i-am-feeling-lucky" ) . is_some ( ) || query. contains ( "::" ) {
@@ -578,6 +583,7 @@ pub(crate) async fn search_handler(
578
583
} else if !query. is_empty ( ) {
579
584
let query_params: String = form_urlencoded:: Serializer :: new ( String :: new ( ) )
580
585
. append_pair ( "q" , & query)
586
+ . append_pair ( "sort" , & sort_by)
581
587
. append_pair ( "per_page" , & RELEASES_IN_RELEASES . to_string ( ) )
582
588
. finish ( ) ;
583
589
@@ -598,6 +604,7 @@ pub(crate) async fn search_handler(
598
604
title,
599
605
results : search_result. results ,
600
606
search_query : Some ( executed_query) ,
607
+ search_sort_by : Some ( sort_by) ,
601
608
next_page_link : search_result
602
609
. next_page
603
610
. map ( |params| format ! ( "/releases/search?paginate={}" , b64. encode( params) ) ) ,
0 commit comments