luci/core/score.rs
1/// Controls whether and how scoring is performed during query execution.
2///
3/// Propagated from the query context down through `Weight` →
4/// `ScorerSupplier` → `Scorer`. Implementations use this to skip expensive
5/// scoring work when scores aren't needed. See [[architecture-query-execution#ScoreMode]].
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum ScoreMode {
8 /// Full scoring required. Default for `must`/`should` clauses.
9 Complete,
10
11 /// No scores needed. Used in filter context (`filter`/`must_not`).
12 /// Implementations skip TF lookup, BM25 computation, and norm loading.
13 CompleteNoScores,
14
15 /// Only top-K scores needed. Enables WAND/MaxScore optimizations:
16 /// skip documents whose max possible contribution cannot enter the
17 /// top-K heap. See [[architecture-query-execution#Disjunction Execution (Should Clauses)]].
18 TopScores,
19}
20
21impl ScoreMode {
22 /// Whether this mode requires score computation.
23 pub fn needs_scores(self) -> bool {
24 matches!(self, ScoreMode::Complete | ScoreMode::TopScores)
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31
32 #[test]
33 fn complete_needs_scores() {
34 assert!(ScoreMode::Complete.needs_scores());
35 }
36
37 #[test]
38 fn complete_no_scores_does_not_need_scores() {
39 assert!(!ScoreMode::CompleteNoScores.needs_scores());
40 }
41
42 #[test]
43 fn top_scores_needs_scores() {
44 assert!(ScoreMode::TopScores.needs_scores());
45 }
46}