Uploaded image for project: 'Hibernate Search'
  1. HSEARCH-1917

Cannot index null or empty values for faceted fields

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.3.0.Final
    • Fix Version/s: 5.5.3.Final, 5.6.0.Alpha2
    • Component/s: backend
    • Labels:
      None

      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:

      @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:

      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,

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: