@@ -174,7 +174,7 @@ impl<TScoreCombiner: ScoreCombiner> BooleanWeight<TScoreCombiner> {
174174 per_occur_scorers. remove ( & Occur :: Must ) . unwrap_or_default ( ) ;
175175 let must_special_scorer_counts = remove_and_count_all_and_empty_scorers ( & mut must_scorers) ;
176176
177- if must_special_scorer_counts. empty_count > 0 {
177+ if must_special_scorer_counts. num_empty_scorers > 0 {
178178 return Ok ( SpecializedScorer :: Other ( Box :: new ( EmptyScorer ) ) ) ;
179179 }
180180
@@ -188,14 +188,14 @@ impl<TScoreCombiner: ScoreCombiner> BooleanWeight<TScoreCombiner> {
188188 let exclude_special_scorer_counts =
189189 remove_and_count_all_and_empty_scorers ( & mut exclude_scorers) ;
190190
191- if exclude_special_scorer_counts. all_count > 0 {
191+ if exclude_special_scorer_counts. num_all_scorers > 0 {
192192 // We exclude all documents at one point.
193193 return Ok ( SpecializedScorer :: Other ( Box :: new ( EmptyScorer ) ) ) ;
194194 }
195195
196196 let minimum_number_should_match = self
197197 . minimum_number_should_match
198- . saturating_sub ( should_special_scorer_counts. all_count ) ;
198+ . saturating_sub ( should_special_scorer_counts. num_all_scorers ) ;
199199
200200 let should_scorers: ShouldScorersCombinationMethod = {
201201 let num_of_should_scorers = should_scorers. len ( ) ;
@@ -244,10 +244,17 @@ impl<TScoreCombiner: ScoreCombiner> BooleanWeight<TScoreCombiner> {
244244 ) )
245245 } ;
246246
247- let positive_scorer = match ( should_scorers, must_scorers) {
247+ let include_scorer = match ( should_scorers, must_scorers) {
248248 ( ShouldScorersCombinationMethod :: Ignored , must_scorers) => {
249249 let boxed_scorer: Box < dyn Scorer > = if must_scorers. is_empty ( ) {
250- if must_special_scorer_counts. all_count + should_special_scorer_counts. all_count
250+ // We do not have any should scorers, nor all scorers.
251+ // There are still two cases here.
252+ //
253+ // If this follows the removal of some AllScorers in the should/must clauses, then
254+ // we match all documents.
255+ //
256+ // Otherwise, it is really just an EmptyScorer.
257+ if must_special_scorer_counts. num_all_scorers + should_special_scorer_counts. num_all_scorers
251258 > 0
252259 {
253260 Box :: new ( AllScorer :: new ( reader. max_doc ( ) ) )
@@ -260,7 +267,7 @@ impl<TScoreCombiner: ScoreCombiner> BooleanWeight<TScoreCombiner> {
260267 SpecializedScorer :: Other ( boxed_scorer)
261268 }
262269 ( ShouldScorersCombinationMethod :: Optional ( should_scorer) , must_scorers) => {
263- if must_scorers. is_empty ( ) && must_special_scorer_counts. all_count == 0 {
270+ if must_scorers. is_empty ( ) && must_special_scorer_counts. num_all_scorers == 0 {
264271 // Optional options are promoted to required if no must scorers exists.
265272 should_scorer
266273 } else {
@@ -289,22 +296,22 @@ impl<TScoreCombiner: ScoreCombiner> BooleanWeight<TScoreCombiner> {
289296 }
290297 } ;
291298 if let Some ( exclude_scorer) = exclude_scorer_opt {
292- let positive_scorer_boxed =
293- into_box_scorer ( positive_scorer , & score_combiner_fn, num_docs) ;
299+ let include_scorer_boxed =
300+ into_box_scorer ( include_scorer , & score_combiner_fn, num_docs) ;
294301 Ok ( SpecializedScorer :: Other ( Box :: new ( Exclude :: new (
295- positive_scorer_boxed ,
302+ include_scorer_boxed ,
296303 exclude_scorer,
297304 ) ) ) )
298305 } else {
299- Ok ( positive_scorer )
306+ Ok ( include_scorer )
300307 }
301308 }
302309}
303310
304311#[ derive( Default , Copy , Clone , Debug ) ]
305312struct AllAndEmptyScorerCounts {
306- all_count : usize ,
307- empty_count : usize ,
313+ num_all_scorers : usize ,
314+ num_empty_scorers : usize ,
308315}
309316
310317fn remove_and_count_all_and_empty_scorers (
@@ -313,10 +320,10 @@ fn remove_and_count_all_and_empty_scorers(
313320 let mut counts = AllAndEmptyScorerCounts :: default ( ) ;
314321 scorers. retain ( |scorer| {
315322 if scorer. is :: < AllScorer > ( ) {
316- counts. all_count += 1 ;
323+ counts. num_all_scorers += 1 ;
317324 false
318325 } else if scorer. is :: < EmptyScorer > ( ) {
319- counts. empty_count += 1 ;
326+ counts. num_empty_scorers += 1 ;
320327 false
321328 } else {
322329 true
@@ -361,7 +368,7 @@ impl<TScoreCombiner: ScoreCombiner + Sync> Weight for BooleanWeight<TScoreCombin
361368
362369 let mut explanation = Explanation :: new ( "BooleanClause. sum of ..." , scorer. score ( ) ) ;
363370 for ( occur, subweight) in & self . weights {
364- if is_positive_occur ( * occur) {
371+ if is_include_occur ( * occur) {
365372 if let Ok ( child_explanation) = subweight. explain ( reader, doc) {
366373 explanation. add_detail ( child_explanation) ;
367374 }
@@ -445,7 +452,7 @@ impl<TScoreCombiner: ScoreCombiner + Sync> Weight for BooleanWeight<TScoreCombin
445452 }
446453}
447454
448- fn is_positive_occur ( occur : Occur ) -> bool {
455+ fn is_include_occur ( occur : Occur ) -> bool {
449456 match occur {
450457 Occur :: Must | Occur :: Should => true ,
451458 Occur :: MustNot => false ,
0 commit comments