Cannot index null or empty values for faceted fields

Description

It seems that it is impossible to have database-stored null or empty strings for domain properties annotated with @Facet.

I tried the configuration below:

1 2 3 4 5 6 7 8 9 10 11 @Entity @Indexed @Table(name = "issuer") public class IndexedObject implements Serializable { @Column @Fields({ @Field, @Field(name = "city_na", analyze = Analyze.NO, indexNullAs = "_null_") }) @Facet(forField = "city_na") private String city; }

a call to persist on a newly created IndexedObject() will yield the following exception:

1 2 3 4 5 6 7 8 Caused by: java.lang.NullPointerException at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.addFacetDocValues(DocumentBuilderIndexedEntity.java:664) at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.buildDocumentFieldsForProperties(DocumentBuilderIndexedEntity.java:646) at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:463) at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:395) at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:299) at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.addWorkToQueue(DocumentBuilderIndexedEntity.java:240) }}

The documentation states (5.4.1.1) that

null values should be avoided

, not that null values are not supported. I do understand that null/empty fields cannot be indexed, but I thought that was the goal of the @Field property indexNullAs, in order to have a marker in the index for null values. However it seems that the conversion from null in the index does not take this setting into account.

The only bypass that I have found is to define a default, non-null, non-empty value to any indexed property used in conjunction with @Facet within my domain object. That is extremely inconvenient since I would have to handle that specific "null" (for example) value throughout my application instead of only when filtering on facets.

Please let me know if I have missed something, or if there is a configuration bypass.

Thanks,

Environment

None

Status

Assignee

Guillaume Smet

Reporter

Julien Serdaru-Barbul

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Components

Fix versions

Affects versions

5.3.0.Final

Priority

Major
Configure