Hi everybody,
I use hibernate (jpa) with hibernate search (3.4.1) and infinispan. One of entities is removed softly by set field removed to true. How to associate this action with removing index of (unindexing) entity?
I've found this post
https://forum.hibernate.org/viewtopic.php?f=9&t=1013755&start=0&hilit=soft+delete which describes one solution, to extend
FullTextIndexEventListener.
In my case new listener may look as below:
Code:
public class SoftDeleteFullTextIndexEventListener extends FullTextIndexEventListener {
private static final long serialVersionUID = 9149462110169911449L;
public SoftDeleteFullTextIndexEventListener(Installation installation) {
super(installation);
}
public void onPostUpdate(PostUpdateEvent event) {
if (used) {
final Object entity = event.getEntity();
if (entity != null && entity instanceof SoftRemovable && ((SoftRemovable) entity).isRemoved()) {
// soft delete, removes search index if entity is marked as removed
super.onPostDelete(new PostDeleteEvent(event.getEntity(), event.getId(), null, event.getPersister(), event.getSession()));
} else {
super.onPostUpdate(event);
}
}
}
}
The problem is that I have no idea how to tell hibernate search to use this new listener instead of default
FullTextIndexEventListener. I've looked into source code but it seams that
FullTextIndexEventListener is hardcoded. How to set my custom listener as default? Is there any other way to implement unindexing on soft delete other than creating fork of hibernate search?
Thanks in advance!