-->
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: Hibernate Search - Additional indexfield (resolved, tnx)
PostPosted: Thu Oct 16, 2008 3:47 am 
Beginner
Beginner

Joined: Fri Sep 26, 2008 2:39 am
Posts: 20
Hibernate Search - Additional indexfield without touching the business objects?

If possible i would like to create an additional lucene-index-field for my objects, without changing the objects source code.

In Detail:

I have multiple business objects which are persisted by hibernate and they are hibernate-search annotated. - I can not touch their sourcecode.

Is there a way to get hibernate-search to write an additional index field named (for example) "summary" which content is created by calling the somewhere (not in the persistent-object) defined method:

static String createSummary(business-object o);

This field should be rewritten every time the object is re indexed.

I would like a hint where to start looking to get this working, since i can't annotate the objects - it has to work generic for any hibernate-search-object in my application.

- JP


Last edited by JP-Ulm on Mon Nov 03, 2008 8:12 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2008 3:33 pm 
Hibernate Team
Hibernate Team

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

the best solution would be to use XML based configuration which can add/override the annotation based configuration. Unfortunately, there is no such XML based configuration yet. You find some hints on how to do this here - http://www.hibernate.org/443.html. If you are interested in this approach let us know and we can help you out as much as can.

Of course you could just try to extend the configuration for your particular need, but that would of course not be generic anymore.

There exists also the possibility to access the Lucene resources directly - http://www.hibernate.org/hib_docs/search/reference/en/html_single/#search-lucene-native. Depending on your use case it might be possible to modify the index yourself. However, I would not recommend this approach.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2008 4:12 am 
Beginner
Beginner

Joined: Fri Sep 26, 2008 2:39 am
Posts: 20
first of all thank you for your answer.

But i think both approaches are not what i am looking for - or I didn't understand them fully - so here are my follow-up question:

Approach 1:

The summery i want to add to each entry in the lucene index is not part of the business-object - that is why annotating it (even without touching the source via xml) does not help - or am I missing something?

Is there a possibility to annotate objects in a way, that a function (not in the object, but somewhere else - with the object as parameter) is called and that result is indexed?

Approach 2:

Accessing lucene natively only gives access to the whole index (and only via a reader?) not to every write operation on the index.

And the index write operation is where i want to be (I guess) to generate my additional info and write it to the index.


As far as I get it, hibernate-search hooks into the hibernate events where objects are written to the database. - then at this point hibernate-search writes the object to the lucene index. - Can i add my operation there somehow?

Thank you all for reading,
JP


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2008 4:32 am 
Hibernate Team
Hibernate Team

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

If you want to fully control which fields get indexed I would recommend a @ClassBridge. In a class bridge you can add as many document fields as you like. In the ClassBridge you can also call your non entity method.

However, since you mentioned that you cannot add the source code you need a way to configure this class bridge. That's why I started mentioning XML configuration.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2008 2:45 am 
Beginner
Beginner

Joined: Fri Sep 26, 2008 2:39 am
Posts: 20
Thank you very much for this deeper explanation, I'm still a hibernate beginner and didn't know about this approach.

I'll use this info as a starting point and later (might take a while) post about the results.

--

So here is what I ended up with: It was decided, that "not touching the source" could be changed to "only adding one line to the source" for the business objects.

The added line of source is a @Classbridge annotation which adds the extra fields to the lucene document.

Thanks again for the support!

Greetings from Ulm,
JP


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.