-->
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: create a Document index from 2 enitities using lucene + ejb3
PostPosted: Thu Oct 12, 2006 11:59 am 
Newbie

Joined: Tue Oct 10, 2006 2:38 pm
Posts: 17
What is the best way to create a Document indexed having info from more than one entities? Having this 2 classes is it possible to create a Document having from ParentEntity name , and from ChildEntity info and id when have insert event in ChildEntity?

maybe adjusting add method from LuceneEventListener?

thanks for any ideea


Code:
@Entity
public class ParentEntity {
   private int id;
   private String name;
   private ChildEntity child;
   
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Keyword(id=true)
    public int getId () {
         return id;
    }
   
    public void setId (int id) {
        this.id = id;
    }


    public void setName(String name) {
      this.name = name;
   }

    public String getName() {
      return name;
   }

   public void setChild(ChildEntity child) {
      this.child = child;
   }

   @OneToMany
   @JoinColumn(name = "data")
   public ChildEntity getChild() {
      return child;
   }

}


Code:
@Entity
@Indexed(index="luceneIndex/test")
public class ChildEntity {
   private int id;
   private String info;
   private ParentEntity parent;
   
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Keyword(id=true)
    public int getId () {
         return id;
    }
   
    public void setId (int id) {
        this.id = id;
    }

   public void setInfo(String info) {
      this.info = info;
   }

   @Text(name = "info")
   public String getInfo() {
      return info;
   }

   public void setParent(ParentEntity parent) {
      this.parent = parent;
   }

   @OneToMany(mappedBy="data")
   public ParentEntity getParent() {
      return parent;
   }


}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 4:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you mean one document containing information of both classes and returning the child id?
You can do that with @FieldBridge but this is only in the lucene integration branch http://anonsvn.jboss.org/repos/hibernate/branches/Lucene_Integration/

I haven't documented that stuff yet,a nd still polishing some area. But I'm interested to hear from your feedback

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 8:17 am 
Newbie

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

I see you want to map the ChildEntity class to a Lucene Document, and you want to add fields with datas from the ParentEntity, right?

So, basically you can add the getter for the ParentEntiti name to the ChildEntity, to make it goes into the Lucene Index, like this:

Code:
@Entity
@Indexed(index="luceneIndex/test")
public class ChildEntity {
   
  // ..
  // stuff in your previous message
  // ..


   @Transient
   @Text(name="name")
   protected String getName() {
       return this.parent.getName()
   }   
 
}


@Transient is needed otherwise this property gets mapped into the database also.

I know, it's a little hack, but it works :-)

_________________
Regards,
Alessio Pace.
http://www.jroller.com/page/alessiopace
-------------------
Rate me if you've found my reply useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 10:41 am 
Newbie

Joined: Tue Oct 10, 2006 2:38 pm
Posts: 17
thanks for all help

I get another solution to fix my problem in the meantime, not as nice as yours.

I created a new class, having same code as org.hibernate.lucene.event.LuceneEventListener, except adding this


Code:
.   private void add(final Object entity, final DocumentBuilder<Object> builder, final Serializable id) {
      Document doc = builder.getDocument( entity, id );
      hack(entity,doc);//<-----
.....}

   protected void hack(Object entity, Document doc) {
//this method will be called in any class who extends this hacked class
   }


      


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 10:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
FYI, I'm not gonna apply such a patch ;-)

_________________
Emmanuel


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.