diff options
author | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-18 15:11:10 -0700 |
---|---|---|
committer | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-18 15:11:10 -0700 |
commit | 99bc14e8adb80d96ba1896b79a6c2ddec32c2513 (patch) | |
tree | b5f472fcc0c70ac45b009fd0439a605de7d995b2 /src | |
parent | 93d11aacd886ddedac176cd1b6fd92029d470a89 (diff) |
If multi-site searching, sort questions by scorev0.2.2
Diffstat (limited to 'src')
-rw-r--r-- | src/stackexchange.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/stackexchange.rs b/src/stackexchange.rs index b6c6a16..ddc3c48 100644 --- a/src/stackexchange.rs +++ b/src/stackexchange.rs @@ -116,7 +116,7 @@ impl StackExchange { /// Parallel searches against the search/advanced endpoint across all configured sites async fn search_advanced(&self, limit: u16) -> Result<Vec<Question>> { - let results = futures::stream::iter(self.config.sites.clone()) + futures::stream::iter(self.config.sites.clone()) .map(|site| { let clone = self.clone(); tokio::spawn(async move { @@ -126,12 +126,17 @@ impl StackExchange { }) .buffer_unordered(CONCURRENT_REQUESTS_LIMIT) .collect::<Vec<_>>() - .await; - results + .await .into_iter() .map(|r| r.map_err(Error::from).and_then(|x| x)) .collect::<Result<Vec<Vec<_>>>>() - .map(|v| v.into_iter().flatten().collect()) + .map(|v| { + let mut all_qs: Vec<Question> = v.into_iter().flatten().collect(); + if self.config.sites.len() > 1 { + all_qs.sort_unstable_by_key(|q| -q.score); + } + all_qs + }) } /// Search against the site's search/advanced endpoint with a given query. |