if ( indexIterator != null && index.length == 1 && ( documentIterator instanceof AbstractIntersectionDocumentIterator || indexIterator.length < MAX_FLAT_DISJUNCTS ) ) {
/* This code is a flat, simplified duplication of what a CounterSetupVisitor would do. It is here just for efficiency. */
numberOfPairs = 0;
/* Find duplicate terms. We score unique pairs term/index with nonzero frequency, as the standard method would do. */
final LongOpenHashSet alreadySeen = new LongOpenHashSet();
for( int i = indexIterator.length; i-- != 0; )
if ( indexIterator[ i ].frequency() != 0 && alreadySeen.add( indexIterator[ i ].termNumber() ) ) numberOfPairs++;
if ( numberOfPairs == indexIterator.length ) flatIndexIterator = indexIterator;
else {
/* We must compact the array, eliminating zero-frequency iterators. */
flatIndexIterator = new IndexIterator[ numberOfPairs ];
alreadySeen.clear();
for( int i = 0, p = 0; i != indexIterator.length; i++ )
if ( indexIterator[ i ].frequency() != 0 && alreadySeen.add( indexIterator[ i ].termNumber() ) ) flatIndexIterator[ p++ ] = indexIterator[ i ];
}
if ( flatIndexIterator.length != 0 ) {
// Some caching of frequently-used values
k1TimesBDividedByAverageDocumentSize = k1 * b * flatIndexIterator[ 0 ].index().numberOfDocuments / flatIndexIterator[ 0 ].index().numberOfOccurrences;