-->
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.  [ 11 posts ] 
Author Message
 Post subject: Hibernate Search conditional de-/indexing
PostPosted: Wed Feb 20, 2008 7:26 pm 
Newbie

Joined: Wed Feb 20, 2008 7:14 pm
Posts: 1
Hi,

I've successfully deployed HSearch with our spring/hibernate/jpa environment and it works as advertised. However, I'm missing a key point.

We rarely delete, we toggle statuses. Using lucene directly we of course control the de-/indexing and those items are removed from the index when their status goes "deleted". But what's the best practice for handling this with HSearch? I know I could store the status on the document and modify the query code to omit it in search results but that would clutter up the index needlessly. And I'd rather not lose the automatic indexing features of HS. Are there hooks I'm missing to facilitate this? TIA.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 8:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I would try the delete flag solution first, I'm pretty sure it's not that bad and it would allow you system to search deleted elements as well.

Otherwise, there is no easy way to achieve what you want. Hibernate Search is flexible enough however to plug arbitrary backend processors. Today there is a Lucene backend processor and a JMS backend processor.

I'm pretty sure you can subclass or fork the LuceneBackendProcessor(Factory) to delete when some objects are updated.

Once you've done that, you can set the processor factory used through this property:

Code:
hibernate.search.worker.backend my.own.BackendImplementationFactory


If it's not enough, you can plug an entirely different system right after the event model.

It's a Worker implementation and can be configured using

Code:
hibernate.search.worker.scope my.own.WorkerImpl


The second solution would require much more qurk I imagine (not sure).


Let me know how it goes, I am interested to see how flexible the extension points are.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 06, 2008 9:28 am 
Newbie

Joined: Mon Oct 22, 2007 7:04 am
Posts: 19
Hmm, we just wandered into this very same problem (or need) at our project. Actually this is a very common use case, where your indexed entity might be going through some transitions (although persisted) before you are ready for it to be indexed. Think "'blog item' not-yet-published", or (in our case) "added 'review' not yet granted by our back-office" for instance.

As I understand your answer above this is not available in out-of-the-box Hibernate Search but could (possibly) be handled by extending at the available extension points.

Wouldn't it be reasonable to be able to specify a predicate class in the @Indexed-tag. The callback-method on the predicate class is then served (by HSearch) the Entity about to be automatically indexed and will answer true/false whether the entity fulfils the requirements for it to actually be indexed. What's your opinion on this Emmanuel? Good or bad idea?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 6:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If the flag solution does not work for some reason we can check this feature, but today I still think the filter or lucene flag is the best approach.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 9:12 am 
Beginner
Beginner

Joined: Thu Feb 28, 2008 4:58 am
Posts: 37
I have deleted flag on Character field. Do I need to write my own StringBridge for Character field? (I see no such bridge in HS)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 9:31 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Yes, making your own StringBridge is really simple and a clean solution.

Otherwise you could use a String instead, configuring the @Column to map it as a Char on the database tables, but this could lead to problems if you use set the value to something longer than 1 char. Use it with a @Length validator in that case.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 2:06 pm 
Beginner
Beginner

Joined: Thu Feb 28, 2008 4:58 am
Posts: 37
I made such StringBridge in one minute ;)

What about more advanced filtering? For example I set max results to 1000, but I need to filter results in complicated way (algorithm for it is complicated)

For example I usually don't see deleted records, but if I have special administrator rights and those records are children of record I own, I can see them

I can post-filter my results, but then I can receive less the 1000 records despite having in index much more records that fit.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 2:22 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
copied from Hibernate Search documentation, chap 5.3. Filters:

Code:
fullTextQuery.enableFullTextFilter("security")


I love this API; isn't this good for you?
You may define all filters you want, nearly as simple as defining your own StringBridge. They will even improve your performance, as sub-selects will be reused as soon as a bug is resolved.

please open new threads for new arguments.

regards,
Sanne


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 22, 2008 7:56 am 
Beginner
Beginner

Joined: Thu Feb 28, 2008 4:58 am
Posts: 37
I have problem with Bridge. I use BLOB field to store different types of document like PDF, DOC etc. How Bridge can know what type of document it processes? I can give bridge a parameter but it's constans.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 22, 2008 9:35 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
I use BLOB field to store different types of document like PDF, DOC etc. How Bridge can know what type of document it processes? I can give bridge a parameter but it's constans.

So you have another field containing the actual type?
Use the Bridge at class level, so you can look at both fields.

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 29, 2008 6:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Well, you can start reading the blob and discover the type, this is how its done usually.

We should add the characterBridge to the distribution, let's open a JIRa issue

_________________
Emmanuel


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