{
indexWriter = new IndexWriter( indexLocation, getAnalyzer(), !exists() );
}
catch ( IOException e )
{
throw new RepositoryIndexException( "Unable to open index", e );
}
try
{
for ( Iterator i = records.iterator(); i.hasNext(); )
{
RepositoryIndexRecord record = (RepositoryIndexRecord) i.next();
if ( record != null )
{
Document document = converter.convert( record );
document.add(
new Field( FLD_PK, record.getPrimaryKey(), Field.Store.NO, Field.Index.UN_TOKENIZED ) );
indexWriter.addDocument( document );
}
}
indexWriter.optimize();
}
catch ( IOException e )
{
throw new RepositoryIndexException( "Failed to add an index document", e );
}
finally
{
closeQuietly( indexWriter );
lastUpdatedTime = System.currentTimeMillis();