Limit the number of elements after reversing it

This commit is contained in:
Clément Renault 2020-12-12 14:21:27 +01:00
parent 9d966a28d3
commit 0e5609d40e
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -177,8 +177,12 @@ impl<'a> Search<'a> {
} }
} }
docids_values.sort_unstable_by_key(|(_, value)| *value); docids_values.sort_unstable_by_key(|(_, value)| *value);
let iter = docids_values.into_iter().map(|(id, _)| id).take(limit); let iter = docids_values.into_iter().map(|(id, _)| id);
if ascending { Ok(iter.collect()) } else { Ok(iter.rev().collect()) } if ascending {
Ok(iter.take(limit).collect())
} else {
Ok(iter.rev().take(limit).collect())
}
} else { } else {
let facet_fn = if ascending { let facet_fn = if ascending {
FacetIter::<f64, FacetLevelValueF64Codec>::new FacetIter::<f64, FacetLevelValueF64Codec>::new
@ -208,8 +212,12 @@ impl<'a> Search<'a> {
} }
} }
docids_values.sort_unstable_by_key(|(_, value)| *value); docids_values.sort_unstable_by_key(|(_, value)| *value);
let iter = docids_values.into_iter().map(|(id, _)| id).take(limit); let iter = docids_values.into_iter().map(|(id, _)| id);
if ascending { Ok(iter.collect()) } else { Ok(iter.rev().collect()) } if ascending {
Ok(iter.take(limit).collect())
} else {
Ok(iter.rev().take(limit).collect())
}
} else { } else {
let facet_fn = if ascending { let facet_fn = if ascending {
FacetIter::<i64, FacetLevelValueI64Codec>::new FacetIter::<i64, FacetLevelValueI64Codec>::new