-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Soft deletes and removing search index
PostPosted: Tue Jan 10, 2012 5:49 am 
Newbie

Joined: Tue Jan 10, 2012 4:07 am
Posts: 6
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!


Top
 Profile  
 
 Post subject: Re: Soft deletes and removing search index
PostPosted: Wed Jan 11, 2012 6:24 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
First step is to set hibernate.search.autoregister_listeners to false. That will stop the auto registration of the default listeners. After that you can add something like that to the properties section in persitence.xml.

Code:
...
<property name="hibernate.ejb.event.post-insert" value="org.hibernate.search.event.FullTextIndexEventListener"/>
<property name="hibernate.ejb.event.post-update" value="org.hibernate.search.event.FullTextIndexEventListener"/>
<property name="hibernate.ejb.event.post-delete" value="org.hibernate.search.event.FullTextIndexEventListener"/>
...


--Hardy


Top
 Profile  
 
 Post subject: Re: Soft deletes and removing search index
PostPosted: Thu Jan 12, 2012 2:48 am 
Newbie

Joined: Tue Jan 10, 2012 4:07 am
Posts: 6
Thanks for help, with those properties almost everything works like a charm. Only MassIndexer requires some additional changes.


Top
 Profile  
 
 Post subject: Re: Soft deletes and removing search index
PostPosted: Thu Jan 12, 2012 4:52 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Quote:
Only MassIndexer requires some additional changes.


What do you mean? Are you still facing a problem?


Top
 Profile  
 
 Post subject: Re: Soft deletes and removing search index
PostPosted: Thu Jan 12, 2012 5:09 am 
Newbie

Joined: Tue Jan 10, 2012 4:07 am
Posts: 6
MassIndexer doesn't use *IndexEventListener, to work with soft deletes correctly custom hibernate.search.batchbackend is required as described here: https://forum.hibernate.org/viewtopic.php?f=9&t=1014096.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.