Fixed
Details
Assignee
Yoann RodièreYoann RodièreReporter
Yoann RodièreYoann RodièreComponents
Sprint
NoneFix versions
Priority
Major
Details
Details
Assignee
Yoann Rodière
Yoann RodièreReporter
Yoann Rodière
Yoann RodièreComponents
Sprint
None
Fix versions
Priority
Created March 3, 2022 at 10:10 AM
Updated July 4, 2022 at 7:01 AM
Resolved March 16, 2022 at 12:28 PM
Currently, projections are always defined in one step:
List<MyPair<String, Genre>> hits = searchSession.search( Book.class ) .select( f -> f.composite( MyPair::new, f.field( "title", String.class ), f.field( "genre", Genre.class ) ) ) .where( f -> f.matchAll() ) .fetchHits( 20 );
This has the disadvantage of exposing all variations of composite projections as many methods directly on the
SearchProjectionFactory
.This means the feature cannot easily be reused for a specialized type of projections, for example the “nested” projection from https://hibernate.atlassian.net/browse/HSEARCH-3943 .
Let’s introduce a more “fluent” API to define composite projections:
List<MyPair<String, Genre>> hits = searchSession.search( Book.class ) .select( f -> f.composite() .add( f.field( "title", String.class ) ) .add( f.field( "genre", Genre.class ) ) .transform( MyPair::new ) ) ) .where( f -> f.matchAll() ) .fetchHits( 20 );
This syntax have the advantage of making the transformations “discoverable”: you add as many components as you need, and then you can type
.
and use IDE auto-completion to discover what you can do with these components (i.e..asList()
, or.transform(Function
, or.transform(BiFunction)
, depending on the number of components).