-->
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 - Custom Bridge value not updating
PostPosted: Tue Sep 17, 2013 12:58 pm 
Newbie

Joined: Tue Sep 17, 2013 12:46 pm
Posts: 5
Initially I need to order by the number of children.
I.e.
TParent contains a Set<TChild> childSet
I need to list TParent's ordered by the childSet.size().
I popped the question here: http://stackoverflow.com/questions/18827149/hibernate-search-order-by-child-count

Don Roby answered suggesting a bridge.
This question is a duplicate of my follow up question here: http://stackoverflow.com/questions/18847238/hibernate-search-custom-bridge-value-not-updating
(I'll populate answers when I have them).

I have a custom bridge. When I insert an entity, the value derived from the custom bridge doesn't appear to be getting updated in the index.

Code:
@Indexed
@Entity
public class TParent  implements java.io.Serializable {

.....
private Set<TChild> TChildSet = new HashSet<TChild>(0);

@ContainedIn
@FieldBridge(impl = CollectionCountBridge.class)
@Field(analyze = Analyze.NO)
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="TParent")
public Set<TChild> getTChildSet() {
   return this.TChildSet;
}


and

Code:
@Indexed
@Entity
public class TChild  implements java.io.Serializable {

.....
private TParent TParent;

@IndexedEmbedded
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="parent_id", nullable=false)
public TParent getTParent() {
    return this.TParent;
}


And the custom bridge

Code:
public class CollectionCountBridge extends IntegerBridge {

   @Override
   public String objectToString(Object object) {
     if (object == null || (!(object instanceof Collection))) {
         return null;
     }
     Collection<?> coll = (Collection<?>) object;
     int size = coll.size();
     System.out.println("col.size(): " + size);
     return super.objectToString(size);
  }

}


I'm listing TParents. I'm trying to order them by the TChildSet count. It works perfectly when I build the index first. I can list TParent's and order them by the by the number of TChild's.

Code:
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, TParent.class);
fullTextQuery.setSort(new Sort(new SortField("TChildSet", SortField.INT, true)));


Now...

When I add a new TChild, the CustomBridge code is executed. I'd expect to see the ordering change as I add TChild's.

I can see that the TChild count is increased (as per the System.out.println() in the CustomBridge code).

However, the query does not order them correctly. The original sort order from when the index was first built remains. Adding new TChild's has no effect on the sort order. I guess the index is not being updated but I'm not sure.

Any help or pointers would be great.

Thanks Very Much

John


Top
 Profile  
 
 Post subject: Re: Hibernate Search - Custom Bridge value not updating
PostPosted: Tue Sep 24, 2013 9:26 am 
Newbie

Joined: Tue Sep 17, 2013 12:46 pm
Posts: 5
It turned out that the problem is due to the index not automatically updating. It has nothing to do with a Sort problem.

The index was not getting automatically updated when the entity was saved due to the fact that index field was not also a DB table field.

The solution is here:

http://stackoverflow.com/questions/18847238/hibernate-search-custom-bridge-value-not-updating/18982895#18982895


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.