Skip to content

Commit db349e3

Browse files
committed
fix: auto downgrade index record option, instead of vint error
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 db349e3

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-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

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

3+
use crate::TantivyError;
4+
35
/// `IndexRecordOption` describes an amount information associated
46
/// with a given indexed field.
57
///
@@ -49,4 +51,17 @@ impl IndexRecordOption {
4951
IndexRecordOption::WithFreqsAndPositions => true,
5052
}
5153
}
54+
55+
/// Downgrades to the next level if provided `IndexRecordOption` is unavailable.
56+
pub fn downgrade(&self, other: IndexRecordOption) -> IndexRecordOption {
57+
use IndexRecordOption::*;
58+
59+
match (other, self) {
60+
(WithFreqsAndPositions, WithFreqsAndPositions) => WithFreqsAndPositions,
61+
(WithFreqs, WithFreqs) => WithFreqs,
62+
(WithFreqsAndPositions, WithFreqs) => WithFreqs,
63+
(WithFreqs, WithFreqsAndPositions) => WithFreqs,
64+
_ => Basic,
65+
}
66+
}
5267
}

0 commit comments

Comments
 (0)