diff --git a/src/core/inverted_index_reader.rs b/src/core/inverted_index_reader.rs index b986b74959..d9fe312666 100644 --- a/src/core/inverted_index_reader.rs +++ b/src/core/inverted_index_reader.rs @@ -135,6 +135,8 @@ impl InvertedIndexReader { term_info: &TermInfo, option: IndexRecordOption, ) -> io::Result { + 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() { diff --git a/src/query/term_query/term_query.rs b/src/query/term_query/term_query.rs index 89b3a7e14e..2e17de7fa7 100644 --- a/src/query/term_query/term_query.rs +++ b/src/query/term_query/term_query.rs @@ -109,6 +109,7 @@ impl TermQuery { } else { IndexRecordOption::Basic }; + Ok(TermWeight::new( self.term.clone(), index_record_option, diff --git a/src/schema/index_record_option.rs b/src/schema/index_record_option.rs index 9550549c56..e44638c320 100644 --- a/src/schema/index_record_option.rs +++ b/src/schema/index_record_option.rs @@ -1,5 +1,7 @@ use serde::{Deserialize, Serialize}; +use crate::TantivyError; + /// `IndexRecordOption` describes an amount information associated /// with a given indexed field. /// @@ -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, + } + } }