worker = new LuceneWorker( workspace );
try {
List<LuceneWorker.WorkWithPayload> queueWithFlatDPs = new ArrayList<LuceneWorker.WorkWithPayload>( queue.size()*2 );
for ( LuceneWork work : queue ) {
DocumentBuilder documentBuilder = searchFactoryImplementor.getDocumentBuilders().get( work.getEntityClass() );
IndexShardingStrategy shardingStrategy = documentBuilder.getDirectoryProviderSelectionStrategy();
if ( PurgeAllLuceneWork.class.isAssignableFrom( work.getClass() ) ) {
DirectoryProvider[] providers = shardingStrategy.getDirectoryProvidersForDeletion(
work.getEntityClass(),
work.getId(),
work.getIdInString()
);
for (DirectoryProvider provider : providers) {
queueWithFlatDPs.add( new LuceneWorker.WorkWithPayload( work, provider ) );
}
}
else if ( AddLuceneWork.class.isAssignableFrom( work.getClass() ) ) {
DirectoryProvider provider = shardingStrategy.getDirectoryProviderForAddition(
work.getEntityClass(),
work.getId(),
work.getIdInString(),
work.getDocument()
);
queueWithFlatDPs.add( new LuceneWorker.WorkWithPayload(work, provider) );
}
else if ( DeleteLuceneWork.class.isAssignableFrom( work.getClass() ) ) {
DirectoryProvider[] providers = shardingStrategy.getDirectoryProvidersForDeletion(
work.getEntityClass(),
work.getId(),
work.getIdInString()
);
for (DirectoryProvider provider : providers) {
queueWithFlatDPs.add( new LuceneWorker.WorkWithPayload(work, provider) );
}
}
else if ( OptimizeLuceneWork.class.isAssignableFrom( work.getClass() ) ) {
DirectoryProvider[] providers = shardingStrategy.getDirectoryProvidersForAllShards();
for (DirectoryProvider provider : providers) {
queueWithFlatDPs.add( new LuceneWorker.WorkWithPayload(work, provider) );
}
}
else {