mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-04 16:22:55 +00:00
fix phrase prefix query (#2043)
* fix phrase prefix query it would fail spectacularly when no doc in the segment would match the phrase part of the query * clippy
This commit is contained in:
@@ -141,7 +141,7 @@ impl<TPostings: Postings> PhrasePrefixScorer<TPostings> {
|
||||
suffix_offset: (max_offset - suffix_pos) as u32,
|
||||
phrase_count: 0,
|
||||
};
|
||||
if !phrase_prefix_scorer.matches_prefix() {
|
||||
if phrase_prefix_scorer.doc() != TERMINATED && !phrase_prefix_scorer.matches_prefix() {
|
||||
phrase_prefix_scorer.advance();
|
||||
}
|
||||
phrase_prefix_scorer
|
||||
@@ -182,7 +182,6 @@ impl<TPostings: Postings> DocSet for PhrasePrefixScorer<TPostings> {
|
||||
}
|
||||
|
||||
fn seek(&mut self, target: DocId) -> DocId {
|
||||
self.phrase_scorer.seek(target);
|
||||
let doc = self.phrase_scorer.seek(target);
|
||||
if doc == TERMINATED || self.matches_prefix() {
|
||||
return doc;
|
||||
|
||||
@@ -258,4 +258,22 @@ mod tests {
|
||||
assert_eq!(phrase_scorer.advance(), TERMINATED);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_phrase_no_match() -> crate::Result<()> {
|
||||
let index = create_index(&["aa dd", "aa aa bb c dd aa bb cc aa dc", " aa bb cd"])?;
|
||||
let schema = index.schema();
|
||||
let text_field = schema.get_field("text").unwrap();
|
||||
let searcher = index.reader()?.searcher();
|
||||
let phrase_query = PhrasePrefixQuery::new(vec![
|
||||
Term::from_field_text(text_field, "aa"),
|
||||
Term::from_field_text(text_field, "cc"),
|
||||
Term::from_field_text(text_field, "d"),
|
||||
]);
|
||||
let enable_scoring = EnableScoring::enabled_from_searcher(&searcher);
|
||||
let weight = phrase_query.weight(enable_scoring).unwrap();
|
||||
let mut phrase_scorer = weight.scorer(searcher.segment_reader(0u32), 1.0)?;
|
||||
assert_eq!(phrase_scorer.advance(), TERMINATED);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user