From 86cb01b243c5f21e7d6afc4989174b8ce6301dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 18 Oct 2018 15:08:04 +0200 Subject: [PATCH] fix: Allow documents to bypass attribute distinction In situations where the attribute is not present. --- src/rank/ranked_stream.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/rank/ranked_stream.rs b/src/rank/ranked_stream.rs index 4de997ab3..e3b28f25e 100644 --- a/src/rank/ranked_stream.rs +++ b/src/rank/ranked_stream.rs @@ -100,7 +100,7 @@ where C: Criterion } pub fn retrieve_distinct_documents(mut self, range: Range) -> Vec - where F: Fn(&DocumentId) -> K, + where F: Fn(&DocumentId) -> Option, K: Hash + Eq, { let mut documents = self.retrieve_all_documents(); @@ -122,8 +122,10 @@ where C: Criterion let mut seen = DistinctMap::new(limit); for document in documents { - let key = distinct(&document.id); - let accepted = seen.digest(key); + let accepted = match distinct(&document.id) { + Some(key) => seen.digest(key), + None => seen.accept_without_key(), + }; if accepted { if seen.len() == range.end { break } @@ -154,7 +156,18 @@ impl DistinctMap { pub fn digest(&mut self, key: K) -> bool { let seen = self.inner.entry(key).or_insert(0); - if *seen < self.limit { *seen += 1; self.len += 1; true } else { false } + if *seen < self.limit { + *seen += 1; + self.len += 1; + true + } else { + false + } + } + + pub fn accept_without_key(&mut self) -> bool { + self.len += 1; + true } pub fn len(&self) -> usize {