From 0e5609d40e1d3fa0240a880f11458dd755815855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sat, 12 Dec 2020 14:21:27 +0100 Subject: [PATCH] Limit the number of elements after reversing it --- src/search/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/search/mod.rs b/src/search/mod.rs index d1850871d..8d190cf87 100644 --- a/src/search/mod.rs +++ b/src/search/mod.rs @@ -177,8 +177,12 @@ impl<'a> Search<'a> { } } docids_values.sort_unstable_by_key(|(_, value)| *value); - let iter = docids_values.into_iter().map(|(id, _)| id).take(limit); - if ascending { Ok(iter.collect()) } else { Ok(iter.rev().collect()) } + let iter = docids_values.into_iter().map(|(id, _)| id); + if ascending { + Ok(iter.take(limit).collect()) + } else { + Ok(iter.rev().take(limit).collect()) + } } else { let facet_fn = if ascending { FacetIter::::new @@ -208,8 +212,12 @@ impl<'a> Search<'a> { } } docids_values.sort_unstable_by_key(|(_, value)| *value); - let iter = docids_values.into_iter().map(|(id, _)| id).take(limit); - if ascending { Ok(iter.collect()) } else { Ok(iter.rev().collect()) } + let iter = docids_values.into_iter().map(|(id, _)| id); + if ascending { + Ok(iter.take(limit).collect()) + } else { + Ok(iter.rev().take(limit).collect()) + } } else { let facet_fn = if ascending { FacetIter::::new