We're upgrading to H.Search 3.4 and it seems that we have hit an incompatibility issue with our old code.
In our domain model we have 'public' and 'private' photos. Public photos' metadata must be indexed and available as fulltext search results on the public web page, private photos don't. We have around 100.000 public photos and 500.000 private photos, so adding them all to the index is not a good option.
That's the code that worked perfectly for the situation stated above and that doesn't work anymore with
Search 3.4.0.CR2 and
H.Core 3.6.3.Final:
Our custom
FullTextIndexEventListener that was checking if the updated entity was "public" or "private" and decided if must be added to the index or not:
Code:
public class SelectiveFullTextIndexEventListener extends FullTextIndexEventListener
{
@Override
public void onPostUpdate(PostUpdateEvent event) {
Object entity = event.getEntity();
if (entity instanceof Photo)
{
Photo photo = ((Photo)entity);
if (Constants.VALUES_PRIVATE.equals(photo.getPrivacy()))
{
if ( used ) {
final Class<?> entityType = event.getEntity().getClass();
if ( searchFactoryImplementor.getDocumentBuildersIndexedEntities().containsKey( entityType )
|| searchFactoryImplementor.getDocumentBuilderContainedEntity( entityType ) != null ) {
processWork( event.getEntity(), event.getId(), WorkType.DELETE, event, false );
if (logger.isDebugEnabled())
logger.debug("Deleted from index after making photo private");
}
} //change from private-->public delete from index
}else {
if (logger.isDebugEnabled())
logger.debug("Added to full text index after updating photo to 'public'");
super.onPostUpdate(event);
}
}
}
}
hibernate.hbm.xml <event/> section:Code:
...
<property name="hibernate.search.autoregister_listeners">true</property>
...
<event type="post-update">
<listener class="CustomFullTextIndexEventListener"/>
</event>
<event type="post-insert">
<listener class="CustomFullTextIndexEventListener"/>
</event>
<event type="post-delete">
<listener class="CustomFullTextIndexEventListener"/>
</event>
<event type="post-collection-recreate">
<listener class="CustomFullTextIndexEventListener"/>
</event>
<event type="post-collection-remove">
<listener class="CustomFullTextIndexEventListener"/>
</event>
<event type="post-collection-update">
<listener class="CustomFullTextIndexEventListener"/>
</event>
<event type="flush">
<listener class="org.hibernate.event.def.DefaultFlushEventListener"/>
<listener class="CustomFullTextIndexEventListener"/>
</event>
The exception raised is:
Code:
2011-04-14 18:42:25,536 => INFO Version:39 - Hibernate Search 3.4.0.CR2
2011-04-14 18:42:25,538 => ERROR FullTextIndexEventListener:122 - FullTextIndexEventListener default constructor is obsolete. Remove all explicitevent listener configuration. As of Hibernate Core 3.6 Hibernate Search will be automatically enabled if it is detected on the classpath.
2011-04-14 18:42:25,540 => ERROR HibernateManager:52 - Unable to instantiate specified event (post-update) listener class: SelectiveFullTextIndexEventListener
org.hibernate.MappingException: Unable to instantiate specified event (post-update) listener class: SelectiveFullTextIndexEventListener
at org.hibernate.cfg.Configuration.setListeners(Configuration.java:2411)
at org.hibernate.cfg.Configuration.parseEvent(Configuration.java:2380)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2302)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2263)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2216)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2131)
Any ideas on how to extend FullTextIndexEventListener in Search 3.4 and Core 3.6.3 to selectively add entities to the lucene index? or alternatively how to do the same without having to give up using listeners? doing it manually is tedious and error prone since we should add code to every DAO updating photos.
Many thanks for your help/ideas
Jordi