We're updating the issue view to help you get more done. 

Unable to extend NumericFieldBridge

Description

Hi,

In the documentation (https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#numeric-field-annotation) we have the example:

Example 27. Defining a custom NumericFieldBridge for BigDecimal

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public class BigDecimalNumericFieldBridge extends NumericFieldBridge { private static final BigDecimal storeFactor = BigDecimal.valueOf(100); @Override public void set(String name, Object value, Document document, LuceneOptions luceneOptions) { if ( value != null ) { BigDecimal decimalValue = (BigDecimal) value; long tmpLong = decimalValue.multiply( storeFactor ).longValue(); Long indexedValue = Long.valueOf( tmpLong ); luceneOptions.addNumericFieldToDocument( name, indexedValue, document ); } } @Override public Object get(String name, Document document) { String fromLucene = document.get( name ); BigDecimal storedBigDecimal = new BigDecimal( fromLucene ); return storedBigDecimal.divide( storeFactor ); } }

By checking the class (org.hibernate.search.bridge.builtin.NumericFieldBridge), I realized that it is now an 'enum' and the constructor is private respectively.

I believe the documentation is incorrect, or a refactoring made it impossible to extend the class.

Particularly, I'm using with Elasticsearch 5.6 like this:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 public class BigDecimalFieldBridge implements MetadataProvidingFieldBridge, TwoWayFieldBridge { @Override public void set(String name, Object value, Document document, LuceneOptions luceneOptions) { if (value != null) { Double indexedValue = ((BigDecimal) value).doubleValue(); luceneOptions.addNumericFieldToDocument(name, indexedValue, document); } } @Override public Object get(String name, Document document) { String fromLucene = document.get(name); return StringHelper.isEmpty(fromLucene) ? null : new BigDecimal(fromLucene); } @Override public String objectToString(Object object) { return object == null ? null : object.toString(); } @Override public void configureFieldMetadata(String name, FieldMetadataBuilder builder) { builder.field(name, FieldType.DOUBLE); } }

If it's just the documentation, I can update it. We can even add more examples, such as a custom FieldBridge to a complex enum too.

Test Cases.

TestCase with error: https://github.com/frekele/hibernate-search-elasticsearch-test-case/tree/HSEARCH-2906
Travis CI log: https://travis-ci.org/frekele/hibernate-search-elasticsearch-test-case/builds/282576064

TestCase without error: https://github.com/frekele/hibernate-search-elasticsearch-test-case/tree/HSEARCH-2906-fixed
Travis CI log: https://travis-ci.org/frekele/hibernate-search-elasticsearch-test-case/builds/282577388

Environment

None

Status

Assignee

Yoann Rodière

Reporter

Leandro Kersting de Freitas

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Components

Fix versions

Affects versions

5.8.1.Final
5.8.0.Final

Priority

Major