`fromRoot` projection

Description

From the original ticket (https://hibernate.atlassian.net/browse/HSEARCH-4827):

If we feel that it’s useful to allow it, but only when the user is explicitly requesting it, we can expose something like the (currently SPI) rootContext method: org.hibernate.search.engine.search.projection.spi.SearchProjectionBuilderFactory#rootContext. We’d end up with something like this:

List<MyBookProjection> hits = searchSession.search( Book.class ) .select( f -> f.composite() .from( f.field( "title", String.class ), f.object( "authors" ) .from( f.fromRoot( f.id() ), // We EXPLICITLY tell HSearch to use the root ID f.field( "authors.firstName", String.class ), f.field( "authors.lastName", String.class ) ) .as( MyBookProjection.Author::new ) .multi() ) .as( MyBookProjection::new ) ) .where( f -> f.matchAll() ) .fetchHits( 20 );

Note there’s a similarity between this fromRoot projection and Elasticsearch's concept of reverse_nested aggregations: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html . Maybe we could introduce that kind of things later, but that’s definitely beyond the scope of this issue.

Activity

Details

Assignee

Reporter

Priority

Created April 20, 2023 at 12:19 PM
Updated September 25, 2023 at 2:48 PM

Flag notifications