Hi,
I have tried interceptor but it doesn't seem to work.
This is my entity class
Code:
@Entity
@Indexed(interceptor=RestrictIndexOnDateInterceptor.class)
@Table(name = "transaction")
public class Transaction implements Serializable {
@Id
@Column(name = "transaction_id")
private BigDecimal transaction_id;
.....
@Column(name = "updated_tm")
private Date updated_tm;
...
public Date getUpdated_tm() {
return updated_tm;
}
...
}
This is the interceptor class
Code:
public class RestrictIndexOnDateInterceptor implements EntityIndexingInterceptor<Transaction> {
private int NO_OF_YEARS_TO_RETAIN_INDEXING = 2;
private final Logger logger = LoggerFactory.getLogger(RestrictIndexOnDateInterceptor.class);
@Override
public IndexingOverride onAdd(Transaction entity) {
logger.info("Adding Index");
if(entity.getUpdated_tm()!=null) {
DateTime lastEntityUpdatedTime = new DateTime(entity.getUpdated_tm());
if(lastEntityUpdatedTime.isBefore(new DateTime().minusYears(NO_OF_YEARS_TO_RETAIN_INDEXING)))
logger.info("Adding Index");
return IndexingOverride.APPLY_DEFAULT;
}
logger.info("Skipping Index");
return IndexingOverride.SKIP;
}
@Override
public IndexingOverride onUpdate(Transaction entity) {
logger.info("Updating Index");
if(entity.getUpdated_tm()!=null) {
DateTime lastEntityUpdatedTime = new DateTime(entity.getUpdated_tm());
if(lastEntityUpdatedTime.isBefore(new DateTime().minusYears(NO_OF_YEARS_TO_RETAIN_INDEXING)))
logger.info("Updating Index");
return IndexingOverride.UPDATE;
}
logger.info("Removing index");
return IndexingOverride.REMOVE;
}
@Override
public IndexingOverride onDelete(Transaction entity) {
return IndexingOverride.APPLY_DEFAULT;
}
@Override
public IndexingOverride onCollectionUpdate(Transaction entity) {
return onUpdate(entity);
}
}
This one creates the indexes
Code:
@Component
public class HibernateSearchIndex {
....
private Future doIndex(Class<?>... classes) {
logger.info("Starting Hibernate Search index");
FullTextEntityManager fullTextEntityManager = entityManagerFactory.createFullTextEntityManager();
Future indexer = fullTextEntityManager.createIndexer(classes)
.progressMonitor(progressMonitor())
.batchSizeToLoadObjects(batchSize)
.threadsToLoadObjects(1)
.start();
fullTextEntityManager.close();
return indexer;
}
.....
}
I tried this program on a subset of data (50K records).
When i try to search for some transaction which is more than 2 years old, it still gives me the result.
Also the log does not show any of the logger.info statements.
Is this interceptor really getting called?