private BulkScorerAndDoc scoreWindow( BulkScorerAndDoc top, LeafCollector collector, LeafCollector singleClauseCollector, Bits acceptDocs, int min, int max) throws IOException { final int windowBase = top.next & ~MASK; // find the window that the next match belongs to final int windowMin = Math.max(min, windowBase); final int windowMax = Math.min(max, windowBase + SIZE); // Fill 'leads' with all scorers from 'head' that are in the right window leads[0] = head.pop(); int maxFreq = 1; while (head.size() > 0 && head.top().next < windowMax) { leads[maxFreq++] = head.pop(); } if (minShouldMatch == 1 && maxFreq == 1) { // special case: only one scorer can match in the current window, // we can collect directly final BulkScorerAndDoc bulkScorer = leads[0]; scoreWindowSingleScorer( bulkScorer, singleClauseCollector, acceptDocs, windowMin, windowMax, max); return head.add(bulkScorer); } else { // general case, collect through a bit set first and then replay scoreWindowMultipleScorers(collector, acceptDocs, windowBase, windowMin, windowMax, maxFreq); return head.top(); } }