-->
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.  [ 6 posts ] 
Author Message
 Post subject: Search: fine grained control over fields of embedded object?
PostPosted: Wed Apr 06, 2011 11:56 am 
Beginner
Beginner

Joined: Tue May 11, 2004 12:20 am
Posts: 33
Hi,
I'm looking into Hibernate Search relational mapping, and @IndexEmbedded.
I saw the "depth" property, but I need better control over fields of embedded objects:

Say I'm indexing Movies and Actors.
- Actors should be searched as stand-alone, and also embedded inside Movie.
- When explicitly searching Actors, I want to search by actor name & biography.
- When searching Movies, I want to search by movie title & actor NAME (but not actor biography).

Code:
// Actors should be searched by name + biography:
@Indexed public class Actor{
     @Field private String name;
     @Field private String biography;
}
// Movies should be searched by title + actor.name (but NOT actor.biography):
@Indexed public class Movie{
     @Field private String title;
     @IndexEmbedded private List<Actor> actors;
}

Thus Tom Cruise gets the following Lucene Document:
- name="Tom Cruise"
- biography="Born in united states, divorced from Nicole..."

While the movie "Mission impossible" gets the following Lucene Document.
- title="Mission Impossible"
- actor.name="Tom Cruise"
- ... but I don't want to generate "actor.biography", it's huge and useless.

Can this be achieved?
Thanks :)


Top
 Profile  
 
 Post subject: Re: Search: fine grained control over fields of embedded object?
PostPosted: Wed Apr 06, 2011 2:10 pm 
Hibernate Team
Hibernate Team

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

currently you cannot do what you want to achieve. I think it would also make the configuration too complex. How would you imagine such a configuration would look like? Personally I don't think that indexing actor.biography is a huge problem. what are your concerns?

Instead of @IndexEmbedded you could write a custom field bridge for the list of actors in movies. Of course you are then loosing the automatic index updates, but looking at your mapping you don't use this anyways afaics (I mean @ContainedIn).

--Hardy


Top
 Profile  
 
 Post subject: Re: Search: fine grained control over fields of embedded object?
PostPosted: Wed Apr 06, 2011 2:53 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
as Hardy, I wonder if you're really getting any advantage from not indexing biography.
Still, you can use a custom fieldbridge combined with @ContainedIn as well.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search: fine grained control over fields of embedded object?
PostPosted: Thu Apr 07, 2011 4:19 am 
Beginner
Beginner

Joined: Tue May 11, 2004 12:20 am
Posts: 33
Thanks very much for both replies :)

1) The reason I don't want to index movies by actor.biography, is size (biography is a huge text, and furthermore duplicated for each movie of the actor). And I'll never use it anyway (who on earth would search for "a movie whose actor is divorced from Nicole Kidman").

2)
Quote:
How would you imagine such a configuration would look like?

I was looking for something like @OverrideEmbeddedFields. But I wasn't trying to push half-baked ideas (realizing the difficulty with several levels of embedding)... just tried to get my application to work.
Code:
// Fictional code...
@Index public class Movie{
     @IndexEmbedded  @OverrideEmbeddedFields(include "name", ignore "biography")
     private List<Actor> actor;
}


3) Custom Bridge sounds good, but could you please clarify what's the difficulty with automatic indexing?
If an actor changes his name, won't it trigger re-indexing of his movies?

Thanks again.


Top
 Profile  
 
 Post subject: Re: Search: fine grained control over fields of embedded object?
PostPosted: Thu Apr 07, 2011 4:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
solmyr72 wrote:
1) The reason I don't want to index movies by actor.biography, is size (biography is a huge text, and furthermore duplicated for each movie of the actor). And I'll never use it anyway (who on earth would search for "a movie whose actor is divorced from Nicole Kidman").


You have to remember here that the actual text is not stored in the index (unless you explicitly do so via Store.YES in @Field). Unless you are using projection there is no need to keep the actual biography text in the index

solmyr72 wrote:
2)
Code:
// Fictional code...
@Index public class Movie{
     @IndexEmbedded  @OverrideEmbeddedFields(include "name", ignore "biography")
     private List<Actor> actor;
}



I see where you are coming from, but as you say this might get hairy w/ several levels of embedding.

solmyr72 wrote:
3) Custom Bridge sounds good, but could you please clarify what's the difficulty with automatic indexing?
If an actor changes his name, won't it trigger re-indexing of his movies?


Not if you don't have a bidirectional relationship and mark the other side with @ContainedIn. Without this information Search would not know that there is something to update. Also there is only so much information which comes via entity changes from Hibernate Core. Have a look at the @ContainedIn documentation.

--Hardy


Top
 Profile  
 
 Post subject: Re: Search: fine grained control over fields of embedded object?
PostPosted: Thu Apr 07, 2011 6:29 am 
Beginner
Beginner

Joined: Tue May 11, 2004 12:20 am
Posts: 33
Thanks very-very much :)


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