System.err.println( "Term frequency was " + f + " and position " + ( f - indexFrequency - 1 ) );
throw e;
}
}
IntArrayList l = new IntArrayList();
ObjectArrayList<int[]> positions = new ObjectArrayList<int[]>();
if ( ! jsapResult.getBoolean( "noSkip" ) ) {
int start = 0, end = 0, result;
try {
for (i = 0; i < index.length; i++) {
pl.expectedUpdates = numberOfTerms[ i ];
pl.start("Verifying all skips in " + index[i] + "...");
for (t = 0; t < numberOfTerms[ i ]; t++) {
l.clear();
positions.clear();
IndexIterator documents = termLists ? indexReader[ i ].documents( terms[ i ].get( t ) ) : indexReader[ i ].documents( t );
int d;
while( ( d = documents.nextDocument() ) != -1 ) {
l.add( d );
if ( index[ i ].hasPositions ) positions.add( ArrayUtils.subarray( documents.positionArray(), 0, documents.count() ) );
}
for( start = 0; start < l.size(); start++ ) {
for( end = start + 1; end < l.size(); end++ ) {
IndexIterator indexIterator = termLists ? indexReader[ i ].documents( terms[ i ].get( t ) ) : indexReader[ i ].documents( t );
result = indexIterator.skipTo( l.getInt( start ) );
if ( indexIterator.document() != l.getInt( start ) || result != l.getInt( start ) ) throw new AssertionError( "Trying to skip to document " + l.getInt( start ) + " (term " + t + ") moved to " + indexIterator.document() + "(skipTo() returned " + result + ")" );
result = indexIterator.skipTo( l.getInt( end ) );
if ( indexIterator.document() != l.getInt( end ) || result != l.getInt( end ) ) throw new AssertionError( "Trying to skip to document " + l.getInt( end ) + " (term " + t + ") after a skip to " + start + " moved to " + indexIterator.document() + "(skipTo() returned " + result + ")" );
if ( index[ i ].hasPositions ) {
// This catches wrong state reconstruction after skips.
indexIterator = termLists ? indexReader[ i ].documents( terms[ i ].get( t ) ) : indexReader[ i ].documents( t );
indexIterator.skipTo( l.getInt( start ) );
if ( indexIterator.document() != l.getInt( start ) ) throw new AssertionError(indexIterator.document() + " != " + l.getInt( start ) );
if ( indexIterator.count() != positions.get( start ).length ) throw new AssertionError(indexIterator.count() + " != " + positions.get( start ).length );
if ( ! Arrays.equals( positions.get( start ), ArrayUtils.subarray( indexIterator.positionArray(), 0, indexIterator.count() ) )
) throw new AssertionError(Arrays.toString( positions.get( start ) ) + "!=" + Arrays.toString( ArrayUtils.subarray( indexIterator.positionArray(), 0, indexIterator.count() ) ) );
indexIterator.skipTo( l.getInt( end ) );
if ( indexIterator.document() != l.getInt( end ) ) throw new AssertionError(indexIterator.document() + " != " + l.getInt( end ) );
if ( indexIterator.count() != positions.get( end ).length ) throw new AssertionError(indexIterator.count() + " != " + positions.get( end ).length );
if ( ! Arrays.equals( positions.get( end ), ArrayUtils.subarray( indexIterator.positionArray(), 0, indexIterator.count() ) )
) throw new AssertionError(Arrays.toString( positions.get( end ) ) + "!=" + Arrays.toString( ArrayUtils.subarray( indexIterator.positionArray(), 0, indexIterator.count() ) ) );
}
}
IndexIterator indexIterator = termLists ? indexReader[ i ].documents( terms[ i ].get( t ) ) : indexReader[ i ].documents( t );
result = indexIterator.skipTo( l.getInt( start ) );
if ( indexIterator.document() != l.getInt( start ) || result != l.getInt( start ) ) throw new AssertionError("Trying to skip to document " + l.getInt( start ) + " (term " + t + ") moved to " + indexIterator.document() + "(skipTo() returned " + result + ")" );
result = indexIterator.skipTo( Integer.MAX_VALUE );
if ( indexIterator.hasNext() || result != Integer.MAX_VALUE ) throw new AssertionError("Trying to skip beyond end of list (term " + t + ") after a skip to " + start + " returned " + result + " (hasNext()=" + indexIterator.hasNext() + ")" );
}