this.searchFactoryImplementor = searchFactoryImplementor;
}
public void run() {
Workspace workspace;
LuceneWorker worker;
workspace = new Workspace( searchFactoryImplementor );
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() ) ) {
/***********hibernate search code**********
DirectoryProvider[] providers = shardingStrategy.getDirectoryProvidersForDeletion(
work.getEntityClass(),
work.getId(),
work.getIdInString()
);
*****************************************/
/****************changed by Jerry*************/
DirectoryProvider[] providers = shardingStrategy.getDirectoryProvidersForDeletion(
work.getEntityClass(),
work.getId(),
work.getIdInString(),
work.getDocument()
);
/*****************************************/
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() ) ) {
/***********hibernate search code**********
DirectoryProvider[] providers = shardingStrategy.getDirectoryProvidersForDeletion(
work.getEntityClass(),
work.getId(),
work.getIdInString()
);
*****************************************/
/****************changed by Jerry*************/
DirectoryProvider[] providers = shardingStrategy.getDirectoryProvidersForDeletion(
work.getEntityClass(),
work.getId(),
work.getIdInString(),
work.getDocument()
);
/*****************************************/
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 {
throw new AssertionFailure( "Unknown work type: " + work.getClass() );
}
}
deadlockFreeQueue(queueWithFlatDPs, searchFactoryImplementor);
checkForBatchIndexing(workspace);
for ( LuceneWorker.WorkWithPayload luceneWork : queueWithFlatDPs ) {
worker.performWork( luceneWork );
}
}
finally {
workspace.clean();
queue.clear();