Do we have any solution for problem specified here .
This is the same case happens in HS result as well.
I know we can use Set instead of List (beg) to prevent this issue.
However code complexity not allowing me to do so.
If any work around for this in HS please let me know
Thanks in advance
Hibernate Search does not have a built-in method of returning hierarchical results.
I’d recommend this approach. It’s slower than alternatives (because you execute two queries), but it’s rather simple and flexible.
- Index both
@IndexedEmbeddedon the property
@IndexedEmbedded(includePaths = "id")on the property
Child.parent. You’ll need to put
Parent.id, of course.
- When querying, query the
Parentfirst; if you need to query
someField. You may need to rely on the
nestedpredicate (HSearch 6 only) in some cases.
- Then, collect the IDs of all matched
- Then execute a search query again, this time on
Child, with an additional predicate to require that the field
parent.idmatches any of the collected IDs.
- Then build a
Map<Parent, List<Child>>from the search results.
EDIT: Alternatively, if you don’t mind a single
Parent being spread on two pages of results, you can simply search on the children, and sort by parent ID. Then building the map for each page should be trivial.