From af91bfa11f9e1ceb2db708c07b4d7cb7eb6cc825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 17 Oct 2018 16:59:39 +0200 Subject: [PATCH] fix: Clamp the document range requested --- src/rank/ranked_stream.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rank/ranked_stream.rs b/src/rank/ranked_stream.rs index 56f228cf9..4de997ab3 100644 --- a/src/rank/ranked_stream.rs +++ b/src/rank/ranked_stream.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::hash::Hash; use std::ops::Range; use std::rc::Rc; -use std::{mem, vec}; +use std::{mem, vec, cmp}; use fnv::FnvHashMap; use fst::Streamer; @@ -92,6 +92,10 @@ where C: Criterion } } + let range = Range { + start: cmp::min(range.start, documents.len()), + end: cmp::min(range.end, documents.len()), + }; documents[range].to_vec() }