Hi,
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
ParentandChild, with@IndexedEmbeddedon the propertyParent.children, and@IndexedEmbedded(includePaths = "id")on the propertyChild.parent. You’ll need to put@GenericFieldonParent.id, of course. - When querying, query the
Parentfirst; if you need to queryChildfields, usechild.someFieldinstead ofsomeField. You may need to rely on thenestedpredicate (HSearch 6 only) in some cases. - Then, collect the IDs of all matched
Parents. - Then execute a search query again, this time on
Child, with an additional predicate to require that the fieldparent.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.