mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-06 01:02:55 +00:00
TermScorer does not handle deletes
This commit is contained in:
@@ -6,16 +6,6 @@ pub use self::term_query::TermQuery;
|
||||
pub use self::term_weight::TermWeight;
|
||||
pub use self::term_scorer::TermScorer;
|
||||
|
||||
use postings::SegmentPostings;
|
||||
use postings::NoDelete;
|
||||
use fastfield::DeleteBitSet;
|
||||
|
||||
pub(crate) type TermScorerWithDeletes = TermScorer<SegmentPostings<DeleteBitSet>>;
|
||||
pub(crate) type TermScorerNoDeletes = TermScorer<SegmentPostings<NoDelete>>;
|
||||
|
||||
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
|
||||
@@ -6,18 +6,19 @@ use query::Scorer;
|
||||
use postings::Postings;
|
||||
use fieldnorm::FieldNormReader;
|
||||
use query::bm25::BM25Weight;
|
||||
use postings::SegmentPostings;
|
||||
|
||||
pub struct TermScorer<TPostings: Postings> {
|
||||
postings: TPostings,
|
||||
pub struct TermScorer {
|
||||
postings: SegmentPostings,
|
||||
fieldnorm_reader: FieldNormReader,
|
||||
similarity_weight: BM25Weight,
|
||||
}
|
||||
|
||||
|
||||
impl<TPostings: Postings> TermScorer<TPostings> {
|
||||
pub fn new(postings: TPostings,
|
||||
impl TermScorer {
|
||||
pub fn new(postings: SegmentPostings,
|
||||
fieldnorm_reader: FieldNormReader,
|
||||
similarity_weight: BM25Weight) -> TermScorer<TPostings> {
|
||||
similarity_weight: BM25Weight) -> TermScorer {
|
||||
TermScorer {
|
||||
postings,
|
||||
fieldnorm_reader,
|
||||
@@ -26,7 +27,7 @@ impl<TPostings: Postings> TermScorer<TPostings> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<TPostings: Postings> DocSet for TermScorer<TPostings> {
|
||||
impl DocSet for TermScorer {
|
||||
fn advance(&mut self) -> bool {
|
||||
self.postings.advance()
|
||||
}
|
||||
@@ -44,7 +45,7 @@ impl<TPostings: Postings> DocSet for TermScorer<TPostings> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<TPostings: Postings> Scorer for TermScorer<TPostings> {
|
||||
impl Scorer for TermScorer {
|
||||
fn score(&mut self) -> Score {
|
||||
let doc = self.doc();
|
||||
let fieldnorm_id = self.fieldnorm_reader.fieldnorm_id(doc);
|
||||
|
||||
@@ -6,8 +6,6 @@ use docset::DocSet;
|
||||
use postings::SegmentPostings;
|
||||
use schema::IndexRecordOption;
|
||||
use super::term_scorer::TermScorer;
|
||||
use fastfield::DeleteBitSet;
|
||||
use postings::NoDelete;
|
||||
use Result;
|
||||
use query::bm25::BM25Weight;
|
||||
|
||||
@@ -24,33 +22,18 @@ impl Weight for TermWeight {
|
||||
let inverted_index = reader.inverted_index(field);
|
||||
let fieldnorm_reader = reader.get_fieldnorms_reader(field);
|
||||
let similarity_weight = self.similarity_weight.clone();
|
||||
if reader.has_deletes() {
|
||||
let postings_opt: Option<SegmentPostings<DeleteBitSet>> =
|
||||
let postings_opt: Option<SegmentPostings> =
|
||||
inverted_index.read_postings(&self.term, self.index_record_option);
|
||||
if let Some(segment_postings) = postings_opt {
|
||||
Ok(box TermScorer::new(segment_postings,
|
||||
fieldnorm_reader,
|
||||
similarity_weight))
|
||||
} else {
|
||||
Ok(box TermScorer::new(
|
||||
SegmentPostings::<NoDelete>::empty(),
|
||||
fieldnorm_reader,
|
||||
similarity_weight))
|
||||
}
|
||||
} else {
|
||||
let postings_opt: Option<SegmentPostings<NoDelete>> =
|
||||
inverted_index.read_postings_no_deletes(&self.term, self.index_record_option);
|
||||
if let Some(segment_postings) = postings_opt {
|
||||
Ok(box TermScorer::new(segment_postings,
|
||||
fieldnorm_reader,
|
||||
similarity_weight))
|
||||
} else {
|
||||
Ok(box TermScorer::new(
|
||||
SegmentPostings::<NoDelete>::empty(),
|
||||
SegmentPostings::empty(),
|
||||
fieldnorm_reader,
|
||||
similarity_weight))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn count(&self, reader: &SegmentReader) -> Result<u32> {
|
||||
|
||||
Reference in New Issue
Block a user