progress.setStatus("Purging index");
log.debug("deleting indexed documents of entity: " + entityClass.getName());
userTx = (UserTransaction)org.jboss.seam.Component.getInstance("org.jboss.seam.transaction.transaction");
userTx.begin();
EntityManager em = (EntityManager) Component.getInstance("entityManager");
FullTextSession ftSession = (FullTextSession)em.getDelegate();
// Delete all documents with "_hibernate_class" term of the selected entity
DirectoryProvider dirProvider = ftSession.getSearchFactory().getDirectoryProviders(entityClass)[0];
IndexReader reader = IndexReader.open(dirProvider.getDirectory());
// TODO: This is using an internal term of HSearch
reader.deleteDocuments(new Term("_hibernate_class", entityClass.getName()));
reader.close();
// Optimize index
progress.setStatus("Optimizing index");
log.debug("optimizing index (merging segments)");
ftSession.getSearchFactory().optimize(entityClass);
userTx.commit();
progress.setStatus("Building index");
log.debug("indexing documents in batches of: " + batchSize);
// Now re-index with HSearch
em = (EntityManager) Component.getInstance("entityManager");
ftSession = (FullTextSession)em.getDelegate();
// TODO: Let's run this in auto-commit mode, assuming we have READ COMMITTED isolation anyway and non-repeatable reads
//userTx.setTransactionTimeout(3600);
//userTx.begin();