mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-06 17:22:54 +00:00
Extracting terms matching query in the document
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user