-->
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: Trying to extend/reuse LuceneEventListener ...
PostPosted: Tue Sep 26, 2006 9:04 am 
Newbie

Joined: Wed Feb 15, 2006 10:17 am
Posts: 13
Location: Rome, Italy
Hi,

I'm trying to make a small thing based on Hibernate-Lucene integration.

Mainly I would like to extend org.hibernate.lucene.event.LuceneEventListener class or reuse it by means of composition but:

* its remove() and add() methods are private (I would have liked to override them)
* its documentBuilders field is private and there are not getters (in a delegating method I would have liked to access that property)

So basically I now have to copy and paste its whole implementation and simply modify what I need..

Am I missing something?

--------------------------
Regards,
Alessio Pace.
http://www.jroller.com/page/alessiopace


Top
 Profile  
 
 Post subject: Re: Trying to extend/reuse LuceneEventListener ...
PostPosted: Tue Sep 26, 2006 1:50 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
puccio wrote:
Hi,
Am I missing something?


Nope.
Simply do that - and write your custom listener.

I did just that - needed some extra annotation handling.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 3:37 pm 
Newbie

Joined: Wed Feb 15, 2006 10:17 am
Posts: 13
Location: Rome, Italy
Ok, thanks, the same thing that I need :-)

------------------
Regards,
Alessio Pace.
http://www.jroller.com/page/alessiopace
-------------------


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 11:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I'm open for discussion regarding the ability to extend the lucene event listeners.
What do you want to do exactly?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 3:46 am 
Newbie

Joined: Wed Feb 15, 2006 10:17 am
Posts: 13
Location: Rome, Italy
Hi Emmanuel,
thanks for the reply.

Basically I would like to reuse the LuceneListener. The simplest thing that I would like to do is to have an hook in the add() method of LuceneEventListener, placed after the creation of a Document by the DocumentBuilder, so that it is possible to add custom Field(s) to the Document which is created.

In this way it would be possible to just reuse the LuceneEvent listener (actually, I had to copy & paste it), in order to add Fields to the mapped Entity->Document. The purpose of that later addition of Fields is to add something meant to be put only in the Lucene Index, without polluting the domain model with @Unstored getters returning constants like the name of the entity class..

So, something like:
Code:
private void add(final Object entity, final DocumentBuilder<Object> builder, final Serializable id) {
    Document doc = builder.getDocument( entity, id );
   
    // XXX abstract protected hook method
    hook(doc); 
               
   // .............
}


What do you think?

---------------
Regards,
Alessio Pace.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 30, 2006 12:27 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
What is the reason for adding constants to the index. Seems like a pollution to me.
When we manage to find the use case, I'll try and think of a proper solution, but subclassing an event seems the worse case senario to me so far, esp becasue I expect to add more behavior to it, like async batching

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 30, 2006 2:01 pm 
Newbie

Joined: Wed Feb 15, 2006 10:17 am
Posts: 13
Location: Rome, Italy
Hi Emmanuel,

Hibernate provides transparent support for mapping Entities to Lucene Index(es), but not the way back (correct me if i'm wrong..).

In a project I'm working which relies on Hibernate, I had to find a simple way to make the Lucene Index(es) to Entities mapping back. I provide you the example which led me to 2 implementation alternatives.

Imagine you have class Foo and class Bar, both are @Indexed, but on two different directories (so, 2 different Lucene indexes).

Now you want to make a ranked search over both of the indexes, through a Lucene MultiIndexSearcher. The search result are Lucene Documents, but you don't know if a Document originated from a Foo or a Bar instance (you would have to check the field names in the Document and the field names on the two classes).

One possibility is to extend the LuceneEventListener so that it is possibile to add a Field named "type" whose value is the canonical name of the domain entity ("x.y.Foo" or "x.y.Bar" in the example).

In this way it would be possible to map back the Lucene Document to a domain entity instance (you know the Class, and the id, you just have to make a findById for the given class and id).

The alternative to rewriting/extending the LuceneEventListener would be otherwise to add to each domain entity a getter stating the type of the class, and make that value go into the Lucene index but *not* going into the relational mapping:

Code:
// class Foo

@Transient
@Text(name="type")
String getType(){
    return "x.y.Foo";    // return "x.y.Bar" in class Bar
}


Maybe there is another solution, but so far I can only see those 2 alternatives that I talked about, which summarizing again are:

1) extending/rewriting the LuceneEventListener, adding that "type" Field there after the DocumetBuilder created the Document (see my previous message).
2) adding the "@Text(..) String getType(){ .. }" to the domain entities (but this method has no business value)

If you can suggest me a better approach (different from "use the Compass Framework" :) I would appreciate a lot :-)

Thanks in advance,
-------------------------------
Alessio Pace.
http://jroller.com/page/alessiopace


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 9:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes I have a better approach.
I already prototyped a query facility on top of Lucene but returning entities :-)

I plan to work on it again soon and push it back to the main branch, but I think it's already working fine.

http://anonsvn.jboss.org/repos/hibernate/branches/Lucene_Integration/HibernateExt/metadata/

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 10:45 am 
Newbie

Joined: Wed Feb 15, 2006 10:17 am
Posts: 13
Location: Rome, Italy
Ah, I didn't know of that branch...

After giving a look at it, it seems cool! :-D And it seems like we adopted the same "trick" of the class name Field into the Lucene Documents. Unfortunately, I coded my solution "externally" from Hibernate code base.

Do you have any idea when it will be merged? I would like to use it in production... :-)

Regards,
Alessio Pace.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 4:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no firm date, I think it will be part of HAN 3.3
I don't know if I will backport that to 3.2

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 4:43 pm 
Newbie

Joined: Wed Feb 15, 2006 10:17 am
Posts: 13
Location: Rome, Italy
thanks for the all the infos and the support.

Regards,
-------------------
Alessio Pace.
http://www.jroller.com/page/alessiopace


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.