Sort AUR results by popularity

This commit is contained in:
kageru 2020-06-09 20:28:19 +02:00
parent f4840462f8
commit 48038fc9b8
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -5,7 +5,7 @@ use std::fmt;
pub fn query_aur(ctx: Context, msg: Message, args: Vec<&str>) { pub fn query_aur(ctx: Context, msg: Message, args: Vec<&str>) {
let query = args.join(" "); let query = args.join(" ");
let response: Response = search( let mut response: Response = search(
&format!( &format!(
"https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg={}", "https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg={}",
&query &query
@ -16,6 +16,11 @@ pub fn query_aur(ctx: Context, msg: Message, args: Vec<&str>) {
send(msg.channel_id, "No results", &ctx); send(msg.channel_id, "No results", &ctx);
return; 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); respond_with_results(msg.channel_id, &response.results, &ctx);
} }
@ -40,8 +45,8 @@ struct Package {
url: String, url: String,
#[serde(rename = "NumVotes")] #[serde(rename = "NumVotes")]
votes: u16, votes: u16,
//Popularity 3.159745 #[serde(rename = "Popularity")]
//OutOfDate null popularity: f32,
} }
impl fmt::Display for Package { impl fmt::Display for Package {