-->
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: 5.5.3 - Sort by collection size no longer working
PostPosted: Sat Jun 04, 2016 3:55 am 
Newbie

Joined: Sat Feb 27, 2016 1:47 am
Posts: 16
Hello, I've been trying to migrate from Hibernate Search 5.5.2 to 5.5.3, and I've run into an issue with one of my sort fields. This is the code that was working with 5.5.2 (or maybe it wasn't working, and just wasn't throwing errors?)

Code:
    public class CollectionCountBridge implements MetadataProvidingFieldBridge {
   
       @Override
       public void configureFieldMetadata(String name, FieldMetadataBuilder builder) {
          builder.field(name, FieldType.INTEGER).sortable(true);
       }
   
       @Override
       public void set(String name, Object object, Document document, LuceneOptions luceneOptions) {
          if (object == null || (!(object instanceof Collection))) {
             return;
          }
          Collection<?> coll = (Collection<?>) object;
          int size = coll.size();
   
          IntField field = new IntField(name, size, (luceneOptions.getStore() != Store.NO) ? Field.Store.YES : Field.Store.NO);
          document.add(field);
       }
   
    }

    ...

    @Field(analyze = Analyze.NO, norms = Norms.YES, index = Index.YES)
   @FieldBridge(impl = CollectionCountBridge.class)
   @IndexedEmbedded
   @OneToMany
   public Set<MyCollection> getMyCollection() {
      return myCollection;
   }


The code essentially stores the size of the collection as a sortable field. This was based on the documentation which suggested if I need to define a sortable field via a bridge, then I have to implement MetadataProvidingFieldBridge to mark it sortable. The documentation however shows only an example for a string field, whereas I need to use a numeric field. http://docs.jboss.org/hibernate/search/ ... annotation

So following the upgrade to 5.5.3 I started getting errors like:

Code:
org.hibernate.search.exception.SearchException: HSEARCH000307: Sort type INT is not compatible with string type of field 'myCollection'


I've tried adding the field to the document in a variety of ways, and nothing seems to work. Some things I've tried:

Code:
luceneOptions.addNumericFieldToDocument(name, size, document);

    document.add(new SortedNumericDocValuesField(name, size));
    //this throws an error on index
    java.lang.IllegalArgumentException: cannot change DocValues type from SORTED_NUMERIC to NUMERIC for field "myCollection"

    public class CollectionCountBridge extends NumberBridge


So, my question is, what is the correct way to add a sortable numeric field to the index, via a bridge, as of 5.5.3?


Top
 Profile  
 
 Post subject: Re: 5.5.3 - Sort by collection size no longer working
PostPosted: Mon Jun 06, 2016 7:17 pm 
Newbie

Joined: Sat Feb 27, 2016 1:47 am
Posts: 16
answered on stack overflow: http://stackoverflow.com/questions/3762 ... er-working


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.