diff --git a/src/query/boolean_query/boolean_weight.rs b/src/query/boolean_query/boolean_weight.rs index f7eb646aa..f62cffb57 100644 --- a/src/query/boolean_query/boolean_weight.rs +++ b/src/query/boolean_query/boolean_weight.rs @@ -9,8 +9,8 @@ use crate::query::score_combiner::{DoNothingCombiner, ScoreCombiner}; use crate::query::term_query::TermScorer; use crate::query::weight::{for_each_docset_buffered, for_each_pruning_scorer, for_each_scorer}; use crate::query::{ - intersect_scorers, AllScorer, BufferedUnionScorer, EmptyScorer, Exclude, Explanation, - Intersection, Occur, RequiredOptionalScorer, Scorer, Weight, + intersect_scorers, AllScorer, BufferedUnionScorer, EmptyScorer, Exclude, Explanation, Occur, + RequiredOptionalScorer, Scorer, Weight, }; use crate::{DocId, Score}; @@ -50,10 +50,9 @@ where TScoreCombiner: ScoreCombiner, { assert!(!scorers.is_empty()); - if scorers.len() == 1 { + if scorers.len() == 1 && !scorers[0].is::() { return SpecializedScorer::Other(scorers.into_iter().next().unwrap()); //< we checked the size beforehand } - { let is_all_term_queries = scorers.iter().all(|scorer| scorer.is::()); if is_all_term_queries { @@ -67,6 +66,9 @@ where { // Block wand is only available if we read frequencies. return SpecializedScorer::TermUnion(scorers); + } else if scorers.len() == 1 { + // Single TermScorer without freq reading — unwrap directly. + return SpecializedScorer::Other(Box::new(scorers.into_iter().next().unwrap())); } else { return SpecializedScorer::Other(Box::new(BufferedUnionScorer::build( scorers,