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 bccb87e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 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
5 changes: 3 additions & 2 deletions src/query/term_query/term_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@ impl TermQuery {
}
};
let scoring_enabled = enable_scoring.is_scoring_enabled();
let index_record_option = if scoring_enabled {
let requested_index_record_option = if scoring_enabled {
self.index_record_option
} else {
IndexRecordOption::Basic
};

Ok(TermWeight::new(
self.term.clone(),
index_record_option,
requested_index_record_option,
bm25_weight,
scoring_enabled,
))
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 bccb87e

Please sign in to comment.