advance, added next

This commit is contained in:
Paul Masurel
2016-08-06 12:01:31 +09:00
parent bf0d072c2d
commit 79158e98eb
2 changed files with 14 additions and 8 deletions

View File

@@ -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<DocId> {
if self.advance() {
Some(self.doc())
}
else {
None
}
}
}

View File

@@ -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());
}