diff --git a/src/postings/docset.rs b/src/postings/docset.rs index 1f182586e..63cf24067 100644 --- a/src/postings/docset.rs +++ b/src/postings/docset.rs @@ -2,6 +2,7 @@ use DocId; use std::borrow::Borrow; use std::borrow::BorrowMut; use std::cmp::Ordering; +use std::iter::Iterator; #[derive(PartialEq, Eq, Debug)] pub enum SkipResult { @@ -34,6 +35,15 @@ pub trait DocSet { } fn doc(&self,) -> DocId; + + fn next(&mut self) -> Option { + if self.advance() { + Some(self.doc()) + } + else { + None + } + } } diff --git a/src/postings/union_postings.rs b/src/postings/union_postings.rs index 876532f95..27b9e49bb 100644 --- a/src/postings/union_postings.rs +++ b/src/postings/union_postings.rs @@ -170,17 +170,13 @@ mod tests { vec!(left, right), multi_term_scorer ); - assert!(union.advance()); - assert_eq!(union.doc(), 1); + assert_eq!(union.next(), Some(1u32)); assert!(abs_diff(union.scorer().score(), 2.182179f32) < 0.001); - assert!(union.advance()); - assert_eq!(union.doc(), 2); + assert_eq!(union.next(), Some(2u32)); assert!(abs_diff(union.scorer().score(), 0.2236068) < 0.001f32); - assert!(union.advance()); - assert_eq!(union.doc(), 3); - assert!(union.advance()); + assert_eq!(union.next(), Some(3u32)); + assert_eq!(union.next(), Some(8u32)); assert!(abs_diff(union.scorer().score(), 0.8944272f32) < 0.001f32); - assert_eq!(union.doc(), 8); assert!(!union.advance()); }