Ensure we don't seek back when reading postings
This works around the debug-only crash when trying to seek
to a doc_id that would have appeared before the current
SegmentPostings cursor.
Since DocSets now come already initialized, `.seek()`ing
without checking if we're already at the desired position
is likely a bug (hence the `debug_assert!` biting me, I
suspect).
On tantivy.git @ 730cceff one can see the subtle bug that
the assertion can catch. Code that once looked like:
let mut scorer = create_scorer();
if scorer.seek(doc) != doc {
...
}
Should now look like:
let mut scorer = create_scorer();
if scorer.doc() > doc || scorer.seek(doc) != doc {
...
}
- Id
- 550b38d90950b2e3158217565cc70ad0c15380ef
- Author
- Caio
- Commit time
- 2020-11-01T10:28:46+01:00
Modified tique/src/topterms.rs
let mut postings =
inverted_index.read_postings_from_terminfo(terminfo, IndexRecordOption::WithFreqs);
+ // XXX SegmentPostings::seek crashes debug builds when the target
+ // is before the current position
+ if postings.doc() > doc_id {
+ continue;
+ }
+
if postings.seek(doc_id) == doc_id {
let term = Term::from_field_text(field, text);
consumer(term, postings.term_freq());