@@ -238,6 +238,36 @@ public void testToString() {
238238 assertTrue ("should contain alpha" , s .contains ("alpha" ));
239239 }
240240
241+ public void testCountDelegatesToInner () throws Exception {
242+ Query inner = new TermQuery (new Term ("body" , "alpha" ));
243+ BayesianScoreQuery bsq = new BayesianScoreQuery (inner , 0.5f , 5.0f );
244+
245+ Weight w = searcher .createWeight (searcher .rewrite (bsq ), ScoreMode .COMPLETE , 1 );
246+ LeafReaderContext context = searcher .getIndexReader ().leaves ().get (0 );
247+
248+ // BayesianScoreQuery only transforms scores; matching docs are unchanged.
249+ // count() should delegate to the inner weight.
250+ int count = w .count (context );
251+ assertEquals (2 , count );
252+
253+ // Verify it matches the inner query's count
254+ Weight innerW = searcher .createWeight (inner , ScoreMode .COMPLETE , 1 );
255+ assertEquals (innerW .count (context ), count );
256+ }
257+
258+ public void testCountWithNoScoring () throws Exception {
259+ // When scoreMode.needsScores() == false, createWeight returns innerWeight directly
260+ Query inner = new TermQuery (new Term ("body" , "alpha" ));
261+ BayesianScoreQuery bsq = new BayesianScoreQuery (inner , 0.5f , 5.0f );
262+
263+ Weight w = searcher .createWeight (searcher .rewrite (bsq ), ScoreMode .COMPLETE_NO_SCORES , 1 );
264+ LeafReaderContext context = searcher .getIndexReader ().leaves ().get (0 );
265+
266+ // Should delegate to inner weight's count
267+ int count = w .count (context );
268+ assertEquals (2 , count );
269+ }
270+
241271 public void testDifferentAlphaBeta () throws Exception {
242272 Query inner = new TermQuery (new Term ("body" , "alpha" ));
243273
0 commit comments