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/ ... annotationSo 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?