-->
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: Updating an entity field all the entity fields reindexed?
PostPosted: Wed Nov 30, 2011 4:12 pm 
Newbie

Joined: Sat Feb 12, 2011 3:49 pm
Posts: 13
If I update an Hibernate entity, all the indexed fields are re-indexed? Well, perhaps this is not the question because I have seen this is true. Lucene can't update a Document, but you need to delete it and add again with the new values.

My problem is that I have a indexed field marked as @Transient and after the update, this field is missing from Lucene index. This is collateral effect of the delete-and-create "update" method. This @Transient field is used to store the extracted text from a PDF, for example. The whole entity is used to store files, as you can guess. Let's call the entity "StoredFile".

I wonder if is possible to create a custom FieldBridge which get the old indexed field content and copy to the new created Lucene Document. The final objective is to avoid the text extraction from PDF and the following indexing process each time a property of the "StoredFile" changes.

Or perhaps there is a better solution?


Top
 Profile  
 
 Post subject: Re: Updating an entity field all the entity fields reindexed?
PostPosted: Fri Dec 02, 2011 4:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

@Transient does not have an effect on indexing. If the property has a value when getting indexed, this value should be available in the Lucene Document for searching.

One problem could be if you persist the entity for the first time (with some data in the transient field which gets indexed) and then load the entity later again from the database. In this case the transient field is of course empty. If you now modify something else in the entity and persist again, the transient field is empty and hence nothing will be indexed and the old indexed value is lost. Is this your problem?

--Hardy


Top
 Profile  
 
 Post subject: Re: Updating an entity field all the entity fields reindexed?
PostPosted: Fri Dec 02, 2011 6:13 am 
Newbie

Joined: Sat Feb 12, 2011 3:49 pm
Posts: 13
Yes, this is my problem? If there is an event thrown when Hibernate Search, commits the modification into the Lucene index, should be nice to attach a class to manage this case. I would retrieve the Lucene's document previously stored before deletion. I expect I can explain it better:

1.- Make a modification to the entity
2.- Make it persist -> Hibernate.Session.update(entity)
3.- Hibernate Search call to Lucene.Index to delete the old Lucene.Document and create a new one.

In step 3, I would like to intercept the call to Lucene and fill the missing entity properties again. Is this possible o I should use Lucene directly?

Regards.


Top
 Profile  
 
 Post subject: Re: Updating an entity field all the entity fields reindexed?
PostPosted: Fri Dec 02, 2011 6:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
There is no event in Hibernate Search, but there are Hibernate/JPA events you could use. If you are using JPA you could for example use @PostLoad.


Top
 Profile  
 
 Post subject: Re: Updating an entity field all the entity fields reindexed?
PostPosted: Fri Dec 02, 2011 2:48 pm 
Newbie

Joined: Sat Feb 12, 2011 3:49 pm
Posts: 13
Ok, thanks.


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.