I am using Hibernate Search with conditional indexing on one of the entity classes. The @Indexed annotation for that entity specifies a custom interceptor, which prevents instances in a certain state from being indexed.
This is working perfectly as expected. However, I notice that when I use a MassIndexer to reindex everything, it ignores my custom interceptor on that entity class. I’ve confirmed through debug mode that the interceptor is never even invoked, and all instances of that entity are indexed even when they fit the criteria for being skipped.
Am I missing something? Is there a method for reindexing in Hibernate Search that DOES utilize any custom interceptors on the entity classes?
UPDATE
I have tried switching to the “old style” approach suggested by Sanne, using this code snippet:
FullTextSession fullTextSession = Search.getFullTextSession(session);
fullTextSession.setFlushMode(FlushMode.MANUAL);
fullTextSession.setCacheMode(CacheMode.IGNORE);
fullTextSession.beginTransaction();
// Kill the current index
fullTextSession.purgeAll(MyEntity.class);
int batchSize = 10;
ScrollableResults results = fullTextSession.createCriteria(MyEntity.class)
.setFetchSize(batchSize)
.scroll(ScrollMode.FORWARD_ONLY);
int index = 0;
while(results.next()) {
// Re-index entites in batches of 10, freeing up memory after each batch
index++;
fullTextSession.index(results.get(0));
if (index % batchSize == 0) {
fullTextSession.flushToIndexes();
fullTextSession.clear();
}
}
fullTextSession.getTransaction().commit();
However, I am seeing the exact same behavior as I was with MassIndexer. The conditional mapping interceptor on MyEntity is not invoked, and all MyEntity instances are indexed whether they should be or not.
No there is not: HSEARCH-1190.
Working on it, contributions and testers welcome!
You could use old-style indexing using a forward-only scrollable until that’s fixed: Using flushToIndexes()