-->
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: @Transient value back to entity
PostPosted: Thu Dec 04, 2008 2:01 pm 
Beginner
Beginner

Joined: Sun Aug 12, 2007 11:22 am
Posts: 44
Location: Sweden
Code:
@Transient
@Field(index = Index.TOKENIZED, store = Store.COMPRESS)
private String content;


The code above is used because I have indexed pdf, word, excel and don't want it saved in the database only in the lucene index. When viewing the document in Luke everything is ok.

The problem I'm having is that I don't get the @Transient value back when loading from database ( As expected maybe ).

When querying the object the field is null. How can I get the text back to the entity? Is there some workaround for this?


Code:
Media media = new Media();
media.setContent( "Parsed content" ); // the @Transíent field
someService.save( media ); // Save to database and lucene

// Another transaction
Media media = someService.getMedia( 1L );
media.getContent(); // This will be null


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2008 4:20 pm 
Beginner
Beginner

Joined: Sun Aug 12, 2007 11:22 am
Posts: 44
Location: Sweden
I've tried @PostLoad and get the doument from there but this solution is not good. I will have to open the index for each entity.

What I would like is a way to register a ResultTransformer that can get both the entities and the lucene documents.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2008 8:00 am 
Hibernate Team
Hibernate Team

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

Since you are using @Transient you are actually not expected to get the data when it is loaded from the database. That's the whole point of transient - not saving property state in the database.

Per default Hibernate Search will execute a search against the Lucene index in order to determine the Hibernate ids for the matching entities. These entities are then loaded from the database using Hibernate Core.

There is a way to get stored data from the index as well. This feature is called projection and allows you to retrieve any property which is stored in the indexes via Store.YES or Store.COMPRESS. However, you will get object arrays back and not Hibernate managed objects. You can also apply a result transformer in order to transform the arrays into some more appropriate data structures.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2008 9:21 am 
Beginner
Beginner

Joined: Sun Aug 12, 2007 11:22 am
Posts: 44
Location: Sweden
Thanks, but why isn't the document list passed to ResultTransformer?

Like List transformList(List collection, List Document ). I know this is from the org.hibernate.transform but it would be nice to populate my entities by myself.

Code:
public interface LuceneResultTransformer extends ResultTransformer{
  public List transformList(List collection, List Document );
}


There must be many scenarios where I don't want to save 100.000 pdf dokument with 300 pages each in the database and only in the lucene index. However, I might want to make a presentation with the first 10 lines ( like Google ) in the document when a search is made.

What is the "Hibernate Search" way of dealing with this ( if there is any )? Would you save all the content in a file in the database to make it lucene searchable and to be able to make a presentation with it in a web application?

// Mathias


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 13, 2008 7:52 am 
Hibernate Team
Hibernate Team

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

regarding getting the Lucene documents passed to the transformer, just add the FullTextQuery.DOCUMENT projection constant. In this case the returned object array will contain the document as well.

Regarding the data, I am not sure whether I would use Lucene to store the pdf data. It feels somehow wrong to use Lucene as data storage in this case. For search purposes the indexed data does not have to be kept in the index once it was processed. In fact storing the original data will blow up the index and eventually slow down searches. Storing the data in the database seems more natural and you can map it lazily in order to retrieve it.

If you really want to use projection you could just store the first 10 lines of the pdf in the Lucene index, together with all other fields you need for displaying the result list. This way you bypass the db for the actual search.
When an actual result is selected you can access the database.

--Hardy


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.