-->
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.  [ 10 posts ] 
Author Message
 Post subject: Intercept Hibernate Search Auto Indexing
PostPosted: Fri Jan 30, 2009 2:29 pm 
Newbie

Joined: Tue Jan 20, 2009 12:55 pm
Posts: 5
Hi,

Can someone suggest the best way to intercept Hibernate search indexing process. Consider a scenario like this:
I have a Hibernate/JPA entity which can be indexed i.e. it is annotated with @Indexed. I have a business requirement that whenever this entity is created/updated/deleted, a set of business rules will be invoked, which will decide whether that entity should be indexed or not. Kindly suggest how to tackle this situation?

Thanks,
Deepa.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2009 5:13 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
there are some solutions:

1) index a boolean flag so you can filter results on it, hiding results marked as "not public". This boolean flag in the entity could contain some code. The drawback is that you get bigger indexes, have some additional cpu consumption indexing stuff you don't want, and possibly as a design having this boolean getter in your model is not very clean.
The good thing is that you can later change your mind and have a special search which can include the hidden results.

2) replace hibernate search's event listener with your own

3) propose a better alternative we could integrate in Search; patches welcome :-) I am thinking of a strategy-parameter to be added to the main annotation

@Indexed(name="myindex",exclusionSelector=myStrategy.class)

Implementing a validator-like interface, and the default strategy would be something returning true at alla times.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2009 12:51 pm 
Newbie

Joined: Tue Jan 20, 2009 12:55 pm
Posts: 5
Sanne,

Thanks for the reply. I thought of trying out the second solution that you mentioned ie writing a custom index event listener instead of using [code]FullTextIndexEventListener[/code]. I have added all event properties to persistence.xml and pointed it to a custom listener class as follows:
<property name="hibernate.ejb.event.post-update"
value="search.event.MyIndexEventListener"/>
[code]processWork()[/code] seems to be the starting point for initiating indexing. For testing purpose I commented out this piece of code, but still indexing is happening. I would appreciate if you could help me to solve this issue?


Thanks,
Deepa


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 7:01 am 
Newbie

Joined: Tue Jan 20, 2009 12:55 pm
Posts: 5
I made the following changes in the configuration file and code:

1. Sethibernate.search.autoregister_listeners = false in persistence.xml
2. Configured events and mapped them to a custom listener class. Eg:
<property name="hibernate.ejb.event.post-update"
value="lucene.search.MyIndexEventListener"/>
3. Written a new custom listener class by extending FullTextIndexEventListener

public class MyIndexEventListener extends FullTextIndexEventListener {

@Override
public void onPostInsert(PostInsertEvent postInsertEvent) {
if(xxxx) return;//add appropriate logic here
super.onPostInsert(postInsertEvent);
}
}

This way I am able to write necessary logic in the event handling methods and control auto indexing. Please suggest if this is the right approach.

Thanks,
Deepa


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2009 9:08 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
yes I think that should to the trick.
The problem is that in future versions the listener could be declared "final", so I think we should integrate a fetaure like this in the main code.

Are you going to take special care about removing Documents from the index for which the "business rule" doesn't apply anymore?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 11, 2009 8:45 pm 
Newbie

Joined: Fri Mar 06, 2009 11:22 am
Posts: 16
I have a similar case for this, essentially I have some entities that would provide no value if indexed so would like to be able to provide a class that would determine if the Entity should be indexed or not. Is this something that is still under consideration?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 4:52 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
It's not currently on the roadmap. IMHO it should be a good feature, but this could raise some discussions on the design of your model, and Emmanuel is striving to keep the stuff clean and simple.

Usually a filter is good enough, and people making queries don't get confused.

If you have a brilliant use case for it, that would be a good reason to implement it. Could you explain the case?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 8:27 am 
Newbie

Joined: Fri Mar 06, 2009 11:22 am
Posts: 16
Sure, basically our system receives various messages and is responsible for "normalizing" those messages to a standard format. All of the normalized messages make sense to index and some of the "unnormalized" messages make sense to index as well, but there are some instances where the information that is within the message has no value added when indexed (i.e. the message is some non human readable message consisting of arrays of numbers and literally no text).

I will take a look at Filters as I have not yet come across these, is there a documentation page that you could point me at?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 4:18 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
How do you plan to separate the valuable information from the numbers and codes? If you're going for text processing, you should IMHO define your own Analyzer to process your messages. That's were Analyzers were designed for, and is an efficient and flexible solution. So in that case you actually don't want to avoid indexing.

the reference is speaking about the filters:
http://www.hibernate.org/hib_docs/search/reference/en/html_single/#d0e2950
Also the book as a full chapter about them and the best practices about it.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 12:28 pm 
Newbie

Joined: Fri Mar 06, 2009 11:22 am
Posts: 16
Thanks I will definitely take a look at writing a custom analyzer, I have not yet had a chance to do any research into this but I am sure there is a bit of documentation.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.