diff --git a/src/lib.rs b/src/lib.rs index 2747fe8ef..93f0fa43b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -169,8 +169,10 @@ mod macros; mod future_result; // Re-exports +pub use columnar; pub use common::{ByteCount, DateTime}; -pub use {columnar, query_grammar, time}; +pub use query_grammar; +pub use time; pub use crate::error::TantivyError; pub use crate::future_result::FutureResult; diff --git a/src/query/bm25.rs b/src/query/bm25.rs index f67ebf95a..ec931de95 100644 --- a/src/query/bm25.rs +++ b/src/query/bm25.rs @@ -83,8 +83,8 @@ thread_local! { /// The cache is shared across all [Bm25Weight] with the same average fieldnorm on the same thread. /// It is stored in a thread local LRU cache. /// -/// On one query all terms on the same field will share the same average fieldnorm, and thus the same cache. -/// This will lower cache pressure. +/// On one query all terms on the same field will share the same average fieldnorm, and thus the +/// same cache. This will lower cache pressure. /// /// Even between queries (on the same thread), the cache will be reused, which allows the cache to /// better learn the memory address of the cache and access patterns. diff --git a/src/query/exclude.rs b/src/query/exclude.rs index 51740fcd1..67a2d9400 100644 --- a/src/query/exclude.rs +++ b/src/query/exclude.rs @@ -112,15 +112,6 @@ where self.underlying_docset.score() } - #[inline] - fn can_score_doc(&self) -> bool { - self.underlying_docset.can_score_doc() - } - - #[inline] - fn score_doc(&mut self, doc: DocId, term_freq: u32) -> Score { - self.underlying_docset.score_doc(doc, term_freq) - } } #[cfg(test)] diff --git a/src/query/scorer.rs b/src/query/scorer.rs index d63d2ac3e..9ffd69892 100644 --- a/src/query/scorer.rs +++ b/src/query/scorer.rs @@ -14,27 +14,34 @@ pub trait Scorer: downcast_rs::Downcast + DocSet + 'static { /// This method will perform a bit of computation and is not cached. fn score(&mut self) -> Score; - /// Returns true if [`Scorer::score_doc`] can score arbitrary buffered docs without + /// Returns true if [`Scorer::score_doc`] can score buffered docs without /// repositioning the scorer. + /// + /// Scorers whose [`Scorer::score_doc`] needs term frequencies must also override + /// [`Scorer::fill_buffer_up_to_with_term_freqs`]. fn can_score_doc(&self) -> bool { false } /// Returns the score for `doc` with its term frequency. fn score_doc(&mut self, _doc: DocId, _term_freq: u32) -> Score { - panic!("score_doc is not supported by this scorer. You need check can_score_doc() before calling this method.") + panic!( + "score_doc is not supported by this scorer. You need check can_score_doc() before \ + calling this method." + ) } - /// Fills docs and term frequencies up to `horizon`. + /// Fills docs up to `horizon`. + /// + /// The default implementation does not fill `term_freqs`. Scorers whose + /// [`Scorer::score_doc`] reads term frequencies must override this method. fn fill_buffer_up_to_with_term_freqs( &mut self, horizon: DocId, docs: &mut [DocId; COLLECT_BLOCK_BUFFER_LEN], - term_freqs: &mut [u32; COLLECT_BLOCK_BUFFER_LEN], + _term_freqs: &mut [u32; COLLECT_BLOCK_BUFFER_LEN], ) -> usize { - let len = DocSet::fill_buffer_up_to(self, horizon, docs); - term_freqs[..len].fill(1); - len + DocSet::fill_buffer_up_to(self, horizon, docs) } } diff --git a/src/query/union/buffered_union.rs b/src/query/union/buffered_union.rs index e64b06202..11e220f0d 100644 --- a/src/query/union/buffered_union.rs +++ b/src/query/union/buffered_union.rs @@ -129,9 +129,9 @@ fn insert_and_score_full_buffer( for (&doc, &term_freq) in docs.iter().zip(term_freqs.iter()) { let delta = doc - min_doc; insert_delta(bitsets, delta); - // TODO: score_doc access the field_norm reader for each _term_, instead of once per doc. - // We could optimize this by caching the field norm for the doc, and reusing it for all - // terms in the doc. + // TODO: score_doc access the field_norm reader for each _term_, instead of once per + // doc. We could optimize this by caching the field norm for the doc, and + // reusing it for all terms in the doc. let score = scorer.score_doc(doc, term_freq); update_score_combiner(score_combiner, delta, doc, score); }