-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Search indexing collection
PostPosted: Wed Mar 12, 2008 7:04 pm 
Newbie

Joined: Mon May 07, 2007 8:37 pm
Posts: 15
I have a class Business, a class User, and a relationship class BusinessUserLink. Here is the mapping:

Code:
@Entity
@Table(name = "business")
@Indexed(index = "business")
public class Business {
// many indexed attributes here
...
}



Code:
@Entity
@Table(name = "user")
@Indexed(index = "user")
public class User {
// few indexed attributes here
...

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "linkingUser")
    private List<BusinessUserLink> businessUserLinks = new ArrayList<BusinessUserLink>(0);
}



Code:
@Entity
@Table(name="business_user_link")
public class BusinessUserLink {
    ...

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "linkedBusinessId")
    private Business linkedBusiness;

    // which business links to it
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "linkingUserId")
    private User linkingUser;
}


Now I want to index this business-user relationship as a field of business index. (Really just the user id. For example, I'd like to search for businesses with a relationship with user 1, 3, 4, 5, ...) Based on doc I would need to add BusinessUserLink collection to the mapping of Business, annotate with @IndexEmbedded, and annotate BusinessUserLink @Indexed and its attribute linkingUser @ContainedIn. This way when a user add/delete a relationship with a business, the business index will be updated.

I am thinking whether this creates a problem because updating index of business is a heavy weight operation, and a business can have many businessUserLinks. While keeping the current hibernate map, a user usually only have less than 10 BusinessUserLink relationships. Is there a way to keep the current hibernate mapping, while only updating a single field of business index when user updates a relationship, or using some query combination to achieve the user filter on business, without updating business index at all?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 3:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
your initial proposal does not work as Lucene cannot "update" documents.

You can use a Filter that you will apply to the HSearch query (Check @FilterDef).
The filter will probably have to query the users and filter by business id.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.