-->
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.  [ 3 posts ] 
Author Message
 Post subject: Filter on @OneToMany, @IndexedEmbedded that can be null
PostPosted: Wed Mar 28, 2012 12:12 pm 
Newbie

Joined: Wed Mar 16, 2011 6:07 pm
Posts: 9
Hi,

I'm using hiberntae search 3.3.0, and I need to now how to implement filter @IndexedEmbedded, @OneToMany collection that can be null.

I have a Person entity:

Code:
@Entity
@Table(name = "person"))
@Indexed(index="Person")
@FullTextFilterDefs( {
    @FullTextFilterDef(name="profileFilter", impl=ProfileFilter.class)
})
public class Person implements java.io.Serializable {

   private List<Profile> profiles = new ArrayList<Profile>(0);

   @OneToMany(fetch = FetchType.LAZY, mappedBy = "person")
   @IndexedEmbedded
   public List<Profile> getProfiles() {
     return this.profiles;
   }
...



This is the Profile entity:

Code:
@Entity
@Table(name = "profile")
@Indexed(index="Profile")
public class Profile implements java.io.Serializable {

  private Person person;
  private long organizationId;

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "person_id")
  @ContainedIn
  public Person getPerson() {
   return this.person;
  }

  @Column(name = "organization_id", nullable = false)
  @Field(index = Index.UN_TOKENIZED, store = Store.YES)
  public long getOrganizationId() {
   return this.organizationId;
  }


I need to enableFullTextFilter with logic ( profile.organizationId == 5 || person.profiles == null). I want to search for persons that don't have profiles or if they have profiles has to be with organizationId == 5. How can be this achieved in hibernate search 3.3.0?


Top
 Profile  
 
 Post subject: Re: Filter on @OneToMany, @IndexedEmbedded that can be null
PostPosted: Thu Mar 29, 2012 4:42 am 
Hibernate Team
Hibernate Team

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

normally null values will get ignored and are not indexed and hence not searchable. One way to get around this is to add an additional @Field on getProfiles using a custom bridge. In this bridge you are adding a special token in case the profile is null. You can then search/filter on this token.

--Hardy


Top
 Profile  
 
 Post subject: Re: Filter on @OneToMany, @IndexedEmbedded that can be null
PostPosted: Thu Mar 29, 2012 4:55 pm 
Newbie

Joined: Wed Mar 16, 2011 6:07 pm
Posts: 9
Hi Hardy,

There is some example code that I can have for reference?

Thank you anyway, for your help.


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