Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Query on ContainedIn field
PostPosted: Wed Nov 23, 2011 4:45 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 208
Hi,

I have a FullTextQuery against the following classes

Code:
@Entity
@Indexed
Post

@OneToMany
List<Comment> comments



@Entity
@Indexed
Comment

@ManyToOne
@ContainedIn
Post post;



Since I'm always only interested in reading only one comment with a post, I don't use @IndexedEmbedded on the Post.comments field. Adding it would needlessly grow the Post index. In stead I use a classbridge for this.

I do want to query comments by Post.

Code:
      FullTextSession fts = Search
      .getFullTextSession(getHibernateTemplate()
            .getSessionFactory().getCurrentSession());
      
      QueryBuilder qb = fts.getSearchFactory().buildQueryBuilder()
      .forEntity(Comment.class).get();

      Query q = qb.bool().must(
         qb.keyword().onField("post.id").matching(postId).createQuery()
      ).createQuery();
      
      FullTextQuery ftq = fts.createFullTextQuery(q, Comment.class)
      .setFirstResult(start)
      .setMaxResults(max);


However, I get this error:
Unable to find field post in Comment.

Adding a classbridge to add the missing field, doesn't help because up to HSearch 4.0, fields added in classbridges are invisible to HSearch. Not even sure, if this has changed when it comes to querying on fields in stead of projecting.

Adding a fieldbridge on the field also doesn't seem to help.

Any ideas on how to accomplish the select in HSearch 3.4?

Kind regards,
Marc


Top
 Profile  
 
 Post subject: Re: Query on ContainedIn field
PostPosted: Wed Nov 23, 2011 5:52 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 208
I managed to resolve this with:

Code:
@Field(name="post.id",index = Index.UN_TOKENIZED, store = Store.NO)
@FieldBridge(impl = ObjectIdBridge.class)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.