if ( indexingIsStandard ) {
final OutputBitStream index = new OutputBitStream( batchBasename + DiskBasedIndex.INDEX_EXTENSION );
final OutputBitStream offsets = new OutputBitStream( batchBasename + DiskBasedIndex.OFFSETS_EXTENSION );
final OutputBitStream posNumBits = new OutputBitStream( batchBasename + DiskBasedIndex.POSITIONS_NUMBER_OF_BITS_EXTENSION );
ByteArrayPostingList baps;
int maxCount = 0, frequency;
long bitLength, postings = 0, prevOffset = 0;
offsets.writeGamma( 0 );
for ( int i = 0; i < numTerms; i++ ) {
baps = termMap.get( termArray[ i ] );
frequency = baps.frequency;
if ( maxCount < baps.maxCount ) maxCount = baps.maxCount;
bitLength = baps.writtenBits();
baps.align();
postings += frequency;
index.writeGamma( frequency - 1 );
// We need special treatment for terms appearing in all documents
if ( frequency == documentCount ) baps.stripPointers( index, bitLength );
else index.write( baps.buffer, bitLength );
frequencies.writeGamma( frequency );
globCounts.writeLongGamma( baps.globCount );
offsets.writeLongGamma( index.writtenBits() - prevOffset );
posNumBits.writeLongGamma( baps.posNumBits );
prevOffset = index.writtenBits();
}
totPostings += postings;
final Properties properties = new Properties();
properties.setProperty( Index.PropertyKeys.DOCUMENTS, documentCount );
properties.setProperty( Index.PropertyKeys.TERMS, numTerms );
properties.setProperty( Index.PropertyKeys.POSTINGS, postings );
properties.setProperty( Index.PropertyKeys.MAXCOUNT, maxCount );
properties.setProperty( Index.PropertyKeys.INDEXCLASS, FileIndex.class.getName() );
properties.addProperty( Index.PropertyKeys.CODING, "FREQUENCIES:GAMMA" );
properties.addProperty( Index.PropertyKeys.CODING, "POINTERS:DELTA" );
if ( completeness.compareTo( Completeness.COUNTS ) >= 0 ) properties.addProperty( Index.PropertyKeys.CODING, "COUNTS:GAMMA" );
if ( completeness.compareTo( Completeness.POSITIONS ) >= 0 ) properties.addProperty( Index.PropertyKeys.CODING, "POSITIONS:DELTA" );
properties.setProperty( Index.PropertyKeys.TERMPROCESSOR, ObjectParser.toSpec( termProcessor ) );
properties.setProperty( Index.PropertyKeys.OCCURRENCES, numOccurrences );
properties.setProperty( Index.PropertyKeys.MAXDOCSIZE, maxDocSize );
properties.setProperty( Index.PropertyKeys.SIZE, index.writtenBits() );
if ( field != null ) properties.setProperty( Index.PropertyKeys.FIELD, field );
properties.save( batchBasename + DiskBasedIndex.PROPERTIES_EXTENSION );
index.close();
offsets.close();
posNumBits.close();
}
else {
final IndexWriter indexWriter = new BitStreamIndexWriter( batchBasename, maxDocInBatch + 1, true, flags );
ByteArrayPostingList bapl;
OutputBitStream obs;
int maxCount = -1, maxFrequency = 0, frequency;
// Compute max frequency and allocate position array.
for ( ByteArrayPostingList b : termMap.values() ) {
b.close();