Extracting terms matching query in the document

This commit is contained in:
Paul Masurel
2018-08-30 09:23:34 +09:00
parent 18814ba0c1
commit a12d211330
6 changed files with 201 additions and 5 deletions

View File

@@ -8,6 +8,8 @@ use query::Weight;
use schema::IndexRecordOption;
use Result;
use Term;
use SkipResult;
use query::weight::MatchingTerms;
pub struct TermWeight {
term: Term,
@@ -38,6 +40,26 @@ impl Weight for TermWeight {
}
}
fn matching_terms(&self,
reader: &SegmentReader,
matching_terms: &mut MatchingTerms) -> Result<()> {
let doc_ids = matching_terms.sorted_doc_ids();
let mut scorer = self.scorer(reader)?;
for doc_id in doc_ids {
match scorer.skip_next(doc_id) {
SkipResult::Reached => {
matching_terms.add_term(doc_id, self.term.clone());
}
SkipResult::OverStep => {}
SkipResult::End => {
break;
}
}
}
Ok(())
}
fn count(&self, reader: &SegmentReader) -> Result<u32> {
if reader.num_deleted_docs() == 0 {
let field = self.term.field();