Skip to content

Commit

Permalink
report if posting list was actually loaded when warming it up (#2309)
Browse files Browse the repository at this point in the history
  • Loading branch information
trinity-1686a authored Jan 29, 2024
1 parent 0e04ec3 commit 3c9297d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/core/inverted_index_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ impl InvertedIndexReader {

/// Warmup a block postings given a `Term`.
/// This method is for an advanced usage only.
pub async fn warm_postings(&self, term: &Term, with_positions: bool) -> io::Result<()> {
///
/// returns a boolean, whether the term was found in the dictionary
pub async fn warm_postings(&self, term: &Term, with_positions: bool) -> io::Result<bool> {
let term_info_opt: Option<TermInfo> = self.get_term_info_async(term).await?;
if let Some(term_info) = term_info_opt {
let postings = self
Expand All @@ -280,23 +282,27 @@ impl InvertedIndexReader {
} else {
postings.await?;
}
Ok(true)
} else {
Ok(false)
}
Ok(())
}

/// Warmup a block postings given a range of `Term`s.
/// This method is for an advanced usage only.
///
/// returns a boolean, whether a term matching the range was found in the dictionary
pub async fn warm_postings_range(
&self,
terms: impl std::ops::RangeBounds<Term>,
limit: Option<u64>,
with_positions: bool,
) -> io::Result<()> {
) -> io::Result<bool> {
let mut term_info = self.get_term_range_async(terms, limit).await?;

let Some(first_terminfo) = term_info.next() else {
// no key matches, nothing more to load
return Ok(());
return Ok(false);
};

let last_terminfo = term_info.last().unwrap_or_else(|| first_terminfo.clone());
Expand All @@ -316,7 +322,7 @@ impl InvertedIndexReader {
} else {
postings.await?;
}
Ok(())
Ok(true)
}

/// Warmup the block postings for all terms.
Expand Down

0 comments on commit 3c9297d

Please sign in to comment.