Querying IndexedEmbedded entities (sometimes) returning wrong result

Description

I’m attaching a test case that demonstrates unwanted search results.

I understand that Hibernate Search uses some tricks to support joined entities, using Apache Lucene, but I’m hoping you can suggest a solution.

I’m searching for “Foo” entities where its “Bar” children must match TWO fields:
bar_name: Bar2
AND
bar_visibility: public

I only want Foo results where a child Bar matches BOTH "Bar2" AND "public".

But, that’s not what’s happening. I’m seeing Foo results when just ONE of the two Bar fields are matched.

This apparently only happens when there are 2 (or more) Bar entities that point to the same Foo entity.

I.e., if you comment out these lines in my attached test case:
Bar bar1 = new Bar(1L, "Bar1", "public", foo1);
foo1.getBars().add(bar1);
s.persist(bar1);
it correctly returns 0 results, as I’d expect.

Please advise.

Attachments

1

Activity

Show:

Yoann Rodière September 13, 2021 at 6:46 AM

This is expected behavior.

By default, for performance reasons, objects in Lucene documents are flattened, i.e. the values of all their fields are put together and merged into the root document. So your query:

Is actually interpreted as:

If you want to preserve the identity of “Bar” children, then you need nested documents, and that’s a feature added in Hibernate Search 6.

More info in this section of the documentation.

I’m going to close this ticket; if you have more questions, please use your topic on the forums.

Rejected

Details

Assignee

Reporter

Labels

Components

Priority

Created September 11, 2021 at 1:11 AM
Updated September 13, 2021 at 6:46 AM
Resolved September 13, 2021 at 6:46 AM