Hibernate Search Order by child-count

后端 未结 1 993
不思量自难忘°
不思量自难忘° 2021-01-26 07:39

Consider:

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

 .....
 private Set TChildSet = new HashSet(0);

         


        
相关标签:
1条回答
  • 2021-01-26 08:08

    In hibernate search, you can make a custom Bridge for this purpose.

    Something along the lines of:

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

    With the custom bridge implementation:

    public class CollectionCountBridge extends PaddedIntegerBridge {
    
        @Override
        public String objectToString(Object object) {
            if (object == null || (!(object instanceof Collection))) {
                return null;
            }
            Collection<?> coll = (Collection<?>) object;
            return super.objectToString(coll.size());
        }
    }
    
    0 讨论(0)
提交回复
热议问题