mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-05-26 13:10:41 +00:00
Added impl Postings for Boxed and ref of postings.
This commit is contained in:
@@ -109,4 +109,4 @@ pub fn intersection<'a>(postings: Vec<SegmentPostings<'a>>) -> IntersectionPosti
|
||||
})
|
||||
.collect();
|
||||
IntersectionPostings::new(boxed_postings)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use DocId;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::BorrowMut;
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum SkipResult {
|
||||
@@ -12,13 +14,57 @@ pub trait Postings {
|
||||
// next needs to be called a first time to point to the correct element.
|
||||
fn next(&mut self,) -> bool;
|
||||
|
||||
fn doc(&self,) -> DocId;
|
||||
|
||||
// after skipping position
|
||||
// the iterator in such a way that doc() will return a
|
||||
// value greater or equal to target.
|
||||
fn skip_next(&mut self, target: DocId) -> SkipResult;
|
||||
|
||||
fn doc(&self,) -> DocId;
|
||||
|
||||
fn doc_freq(&self,) -> usize;
|
||||
}
|
||||
|
||||
impl<TPostings: Postings> Postings for Box<TPostings> {
|
||||
fn next(&mut self,) -> bool {
|
||||
let unboxed: &mut TPostings = self.borrow_mut();
|
||||
unboxed.next()
|
||||
}
|
||||
|
||||
fn skip_next(&mut self, target: DocId) -> SkipResult {
|
||||
let unboxed: &mut TPostings = self.borrow_mut();
|
||||
unboxed.skip_next(target)
|
||||
}
|
||||
|
||||
fn doc(&self,) -> DocId {
|
||||
let unboxed: &TPostings = self.borrow();
|
||||
unboxed.borrow().doc()
|
||||
}
|
||||
|
||||
fn doc_freq(&self,) -> usize {
|
||||
let unboxed: &TPostings = self.borrow();
|
||||
unboxed.doc_freq()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, TPostings: Postings> Postings for &'a mut TPostings {
|
||||
fn next(&mut self,) -> bool {
|
||||
let unref: &mut TPostings = *self;
|
||||
unref.next()
|
||||
}
|
||||
|
||||
fn skip_next(&mut self, target: DocId) -> SkipResult {
|
||||
let unref: &mut TPostings = *self;
|
||||
unref.skip_next(target)
|
||||
}
|
||||
|
||||
fn doc(&self,) -> DocId {
|
||||
let unref: &TPostings = *self;
|
||||
unref.doc()
|
||||
}
|
||||
|
||||
|
||||
fn doc_freq(&self,) -> usize {
|
||||
let unref: &TPostings = *self;
|
||||
unref.doc_freq()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user