Hi everybody,
Is it possible to customise
MassIndexer to not index all entities of given type but only those that aren't soft deleted? In my case soft deleted entities are entities that have 'removed' field set to true.
If
MassIndexer uses
FullTextIndexEventListener then this question is related to
https://forum.hibernate.org/viewtopic.php?f=9&t=1014095 and below code may help:
Code:
public class SoftDeleteFullTextIndexEventListener extends FullTextIndexEventListener {
private static final long serialVersionUID = 9149462110169911449L;
public SoftDeleteFullTextIndexEventListener(Installation installation) {
super(installation);
}
public void onPostInsert(PostInsertEvent event) {
if ( used ) {
final Object entity = event.getEntity();
if ( entity != null && entity instanceof SoftRemovable && ((SoftRemovable) entity).isRemoved()) {
// entity is marked as removed so don't index
return;
} else {
super.onPostInsert(event);
}
}
}
}