I already have the FullTextEntityManager via Seam injection. If Hibernate Search is available, Seam will inject a FullTextEntityManager instead of the HibernateEntityManager.
FullTextEntityManager doesn't offer ALL the same functionality as a FullTextSession.
IE: (From the documention in Hibernate Search)
Code:
fullTextSession.setFlushMode(FlushMode.MANUAL);
fullTextSession.setCacheMode(CacheMode.IGNORE);
transaction = fullTextSession.beginTransaction();
//Scrollable results will avoid loading too many objects in memory
ScrollableResults results = fullTextSession.createCriteria( Email.class ).scroll( ScrollMode.FORWARD_ONLY );
int index = 0;
while( results.next() ) {
index++;
fullTextSession.index( results.get(0) ); //index each element
if (index % batchSize == 0) s.clear(); //clear every batchSize since the queue is processed
}
transaction.commit();
You don't have access to setFlushMode, cache and createCriteria to retrieve ScrollableResults.
FullTextEntityManager implements the javax.persistence.EntityManager, not HibernateEntityManager which provides access to the "Session".
It would be nice to have access to the "Session" from the FullTextEntityManager and the getSession method return a Session interface that can be cast to a FullTextSession.
Note: This is done in the app server with JTA. Unfortunately, the docs don't truly address this. They examples are theoretical.
I'd like to know how others are "ReIndexing" their Hibernate Search FROM WITHIN THE APP SERVER. I've thought of doing it outside the app server, but I'm afraid that would require bringing the server down for maintenance because of concurrent access to the indexes. Not really an option if you reindexing process could take a long time.