indexWriter = new IndexWriter( indexLocation, indexHandlers.getAnalyzer(), !exists() );
indexWriter.setMaxFieldLength( MAX_FIELD_LENGTH );
}
catch ( IOException e )
{
throw new RepositoryIndexException( "Unable to open index", e );
}
try
{
for ( Iterator i = records.iterator(); i.hasNext(); )
{
LuceneRepositoryContentRecord record = (LuceneRepositoryContentRecord) i.next();
if ( record != null )
{
Document document = indexHandlers.getConverter().convert( record );
indexWriter.addDocument( document );
}
}
indexWriter.optimize();
}
catch ( IOException e )
{
throw new RepositoryIndexException( "Failed to add an index document", e );
}
finally
{
closeQuietly( indexWriter );
}