From 48038fc9b855616efbbed7846fc65ac1b33c9bd1 Mon Sep 17 00:00:00 2001 From: kageru Date: Tue, 9 Jun 2020 20:28:19 +0200 Subject: [PATCH] Sort AUR results by popularity --- src/commands/aur.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/commands/aur.rs b/src/commands/aur.rs index 9c42895..ff0a047 100644 --- a/src/commands/aur.rs +++ b/src/commands/aur.rs @@ -5,7 +5,7 @@ use std::fmt; pub fn query_aur(ctx: Context, msg: Message, args: Vec<&str>) { let query = args.join(" "); - let response: Response = search( + let mut response: Response = search( &format!( "https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg={}", &query @@ -16,6 +16,11 @@ pub fn query_aur(ctx: Context, msg: Message, args: Vec<&str>) { send(msg.channel_id, "No results", &ctx); return; } + response.results.sort_by(|a, b| { + a.popularity + .partial_cmp(&b.popularity) + .unwrap_or(std::cmp::Ordering::Less) + }); respond_with_results(msg.channel_id, &response.results, &ctx); } @@ -40,8 +45,8 @@ struct Package { url: String, #[serde(rename = "NumVotes")] votes: u16, - //Popularity 3.159745 - //OutOfDate null + #[serde(rename = "Popularity")] + popularity: f32, } impl fmt::Display for Package {