Range queries on embedded Date fields won't return the expected results

Description

Searching on a numeric field that was indexed through an @IndexedEmbedded will return each and every document (i.e. the filter won't apply) for a [value TO *] query and will return no document for a [value1 TO value2] query. This happens when using the Hibernate Search DSL to build range queries.

I ran the test case in debug mode, and it seems that the problem starts here when building the query:

The problem is that fieldDescriptor is null for embedded fields, which makes the DSL fall back to some Infinispan-related magic, which doesn't consider Date to be a numeric indexed type. This is why the query becomes a keyword-range query ( ?) instead of a numeric-range query.

I searched around a little, and indeed it seems that this method, which initializes the field descriptors of a type descriptor, doesn't consider embedded fields:

The property descriptors don't include the embedded fields, since they are built that way:

... which won't do since the fieldMetadataSet on propertyMetadata doesn't include embedded fields.

I see two solutions:

1. Either we change the propertyMetadata so that it also includes a embeddedFieldsMetadataSet (and we initialize it, and we use it in createOrMergePropertyDescriptor())
2. OR we change IndexedTypeDescriptorImpl so that, in some way, it uses typeMetadata.getEmbeddedTypeMetadata() in the createAllFieldDescriptors() method.

Test case here : https://github.com/hibernate/hibernate-search/pull/958

Environment

Any (test case provided).

Status

Assignee

Yoann Rodière

Reporter

Yoann Rodière

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Components

Fix versions

Affects versions

Priority

Blocker
Configure