5.6. Indexing

5.6. Indexing

It is sometimes useful to index an object event if this object is not inserted nor updated to the database. This is especially true when you want to build your index the first time. You can achieve that goal using the FullTextSession.

FullTextSession fullTextSession = Search.createFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
for (Customer customer : customers) {
    fullTextSession.index(customer);
}
tx.commit(); //index are written at commit time

For maximum efficiency, Hibernate Search batch index operations which and execute them at commit time (Note: you don't need to use org.hibernate.Transaction in a JTA environment).