Sort AUR results by popularity
This commit is contained in:
parent
f4840462f8
commit
48038fc9b8
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user