Skip to content

Commit

Permalink
fix: auto downgrade index record option, instead of vint error (#1857)
Browse files Browse the repository at this point in the history
Prev: thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: IoError(Custom { kind: InvalidData, error: "Reach end of buffer while reading VInt" })', src/main.rs:46:14
Now: Automatic downgrade to next available level
  • Loading branch information
PSeitz authored Feb 10, 2023
1 parent 7a9befd commit 36c6138
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/inverted_index_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ impl InvertedIndexReader {
term_info: &TermInfo,
option: IndexRecordOption,
) -> io::Result<SegmentPostings> {
let option = option.downgrade(self.record_option);

let block_postings = self.read_block_postings_from_terminfo(term_info, option)?;
let position_reader = {
if option.has_positions() {
Expand Down
1 change: 1 addition & 0 deletions src/query/term_query/term_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl TermQuery {
} else {
IndexRecordOption::Basic
};

Ok(TermWeight::new(
self.term.clone(),
index_record_option,
Expand Down
13 changes: 13 additions & 0 deletions src/schema/index_record_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@ impl IndexRecordOption {
IndexRecordOption::WithFreqsAndPositions => true,
}
}

/// Downgrades to the next level if provided `IndexRecordOption` is unavailable.
pub fn downgrade(&self, other: IndexRecordOption) -> IndexRecordOption {
use IndexRecordOption::*;

match (other, self) {
(WithFreqsAndPositions, WithFreqsAndPositions) => WithFreqsAndPositions,
(WithFreqs, WithFreqs) => WithFreqs,
(WithFreqsAndPositions, WithFreqs) => WithFreqs,
(WithFreqs, WithFreqsAndPositions) => WithFreqs,
_ => Basic,
}
}
}

0 comments on commit 36c6138

Please sign in to comment.