Skip to content

Commit 36c6138

Browse files
authored
fix: auto downgrade index record option, instead of vint error (#1857)
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
1 parent 7a9befd commit 36c6138

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/core/inverted_index_reader.rs

+2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ impl InvertedIndexReader {
135135
term_info: &TermInfo,
136136
option: IndexRecordOption,
137137
) -> io::Result<SegmentPostings> {
138+
let option = option.downgrade(self.record_option);
139+
138140
let block_postings = self.read_block_postings_from_terminfo(term_info, option)?;
139141
let position_reader = {
140142
if option.has_positions() {

src/query/term_query/term_query.rs

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ impl TermQuery {
109109
} else {
110110
IndexRecordOption::Basic
111111
};
112+
112113
Ok(TermWeight::new(
113114
self.term.clone(),
114115
index_record_option,

src/schema/index_record_option.rs

+13
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,17 @@ impl IndexRecordOption {
4949
IndexRecordOption::WithFreqsAndPositions => true,
5050
}
5151
}
52+
53+
/// Downgrades to the next level if provided `IndexRecordOption` is unavailable.
54+
pub fn downgrade(&self, other: IndexRecordOption) -> IndexRecordOption {
55+
use IndexRecordOption::*;
56+
57+
match (other, self) {
58+
(WithFreqsAndPositions, WithFreqsAndPositions) => WithFreqsAndPositions,
59+
(WithFreqs, WithFreqs) => WithFreqs,
60+
(WithFreqsAndPositions, WithFreqs) => WithFreqs,
61+
(WithFreqs, WithFreqsAndPositions) => WithFreqs,
62+
_ => Basic,
63+
}
64+
}
5265
}

0 commit comments

Comments
 (0)