Skip to content

Commit

Permalink
fix: auto downgrade index record option, instead of vint error
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 committed Feb 10, 2023
1 parent 7a9befd commit db349e3
Show file tree
Hide file tree
Showing 3 changed files with 18 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
15 changes: 15 additions & 0 deletions src/schema/index_record_option.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use serde::{Deserialize, Serialize};

use crate::TantivyError;

/// `IndexRecordOption` describes an amount information associated
/// with a given indexed field.
///
Expand Down Expand Up @@ -49,4 +51,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 db349e3

Please sign in to comment.