Skip to content

Commit

Permalink
fix: approximate_next should matches
Browse files Browse the repository at this point in the history
  • Loading branch information
jtong11 committed Oct 9, 2020
1 parent 82c3668 commit c9f4283
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/core/search/query/filter_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use core::codec::Codec;
use core::index::reader::LeafReaderContext;
use core::search::explanation::Explanation;
use core::search::query::{Query, TermQuery, Weight};
use core::search::scorer::{two_phase_next, FeatureResult, Scorer};
use core::search::scorer::{FeatureResult, Scorer};
use core::search::searcher::SearchPlanBuilder;
use core::search::DocIterator;
use core::search::{DocIterator, NO_MORE_DOCS};
use core::util::DocId;
use core::util::IndexedContext;
use error::Result;
Expand Down Expand Up @@ -157,19 +157,31 @@ struct FilterScorer {
filters: Vec<Box<dyn LeafFilterFunction>>,
}

impl FilterScorer {
fn two_phase_next(&mut self) -> Result<DocId> {
let mut doc = self.doc_id();
loop {
if doc == NO_MORE_DOCS {
return Ok(NO_MORE_DOCS);
} else if self.matches()? {
return Ok(doc);
}
doc = self.scorer.approximate_next()?;
}
}
}

impl DocIterator for FilterScorer {
fn doc_id(&self) -> DocId {
self.scorer.doc_id()
}

fn next(&mut self) -> Result<DocId> {
self.approximate_next()?;
two_phase_next(self)
self.approximate_next()
}

fn advance(&mut self, target: DocId) -> Result<DocId> {
self.approximate_advance(target)?;
two_phase_next(self)
self.approximate_advance(target)
}

fn cost(&self) -> usize {
Expand All @@ -196,11 +208,13 @@ impl DocIterator for FilterScorer {
}

fn approximate_next(&mut self) -> Result<DocId> {
self.scorer.approximate_next()
self.scorer.approximate_next()?;
self.two_phase_next()
}

fn approximate_advance(&mut self, target: DocId) -> Result<DocId> {
self.scorer.approximate_advance(target)
self.scorer.approximate_advance(target)?;
self.two_phase_next()
}
}

Expand Down

0 comments on commit c9f4283

Please sign in to comment.