Interface SearchProjectionFactory<R,E>
- Type Parameters:
R
- The type of entity references, i.e. the type of objects returned forentity reference projections
.E
- The type of entities, i.e. the type of objects returned forentity projections
.
- All Known Subinterfaces:
ElasticsearchSearchProjectionFactory<R,
,E> ExtendedSearchProjectionFactory<S,
,R, E> LuceneSearchProjectionFactory<R,
E>
- All Known Implementing Classes:
AbstractSearchProjectionFactory
Field paths
By default, field paths passed to this DSL are interpreted as absolute, i.e. relative to the index root.
However, a new, "relative" factory can be created with withRoot(String)
:
the new factory interprets paths as relative to the object field passed as argument to the method.
This can be useful when calling reusable methods that can apply the same projection on different object fields that have same structure (same sub-fields).
Such a factory can also transform relative paths into absolute paths using toAbsolutePath(String)
;
this can be useful for native projections in particular.
-
Method Summary
Modifier and TypeMethodDescriptionStarts the definition of a composite projection, which will combine multiple given projections.default <P1,
P2, T> CompositeProjectionOptionsStep<?, T> composite
(BiFunction<P1, P2, T> transformer, ProjectionFinalStep<P1> dslFinalStep1, ProjectionFinalStep<P2> dslFinalStep2) Deprecated.default <P1,
P2, T> CompositeProjectionOptionsStep<?, T> composite
(BiFunction<P1, P2, T> transformer, SearchProjection<P1> projection1, SearchProjection<P2> projection2) Deprecated.Use.composite().from( projection1, projection2 ).as( transformer )
instead.default <T> CompositeProjectionOptionsStep<?,
T> composite
(Function<List<?>, T> transformer, ProjectionFinalStep<?>... dslFinalSteps) Deprecated.Use.composite().from( dslFinalSteps ).asList( transformer )
instead.default <T> CompositeProjectionOptionsStep<?,
T> composite
(Function<List<?>, T> transformer, SearchProjection<?>... projections) Deprecated.Use.composite().from( projections ).asList( transformer )
instead.default <P,
T> CompositeProjectionOptionsStep<?, T> composite
(Function<P, T> transformer, ProjectionFinalStep<P> dslFinalStep) Deprecated.Use.composite().from( dslFinalStep ).as( transformer )
instead.default <P,
T> CompositeProjectionOptionsStep<?, T> composite
(Function<P, T> transformer, SearchProjection<P> projection) Deprecated.Use.composite().from( projection ).as( transformer )
instead.default CompositeProjectionValueStep<?,
List<?>> composite
(ProjectionFinalStep<?>... dslFinalSteps) Create a projection that will compose aList
based on the given almost-built projections.composite
(SearchProjection<?>... projections) Create a projection that will compose aList
based on the given projections.default <P1,
P2, P3, T>
CompositeProjectionOptionsStep<?,T> composite
(TriFunction<P1, P2, P3, T> transformer, ProjectionFinalStep<P1> dslFinalStep1, ProjectionFinalStep<P2> dslFinalStep2, ProjectionFinalStep<P3> dslFinalStep3) Deprecated.Use.composite().from( dslFinalStep1, dslFinalStep2, dslFinalStep3 ).as( transformer )
instead.default <P1,
P2, P3, T>
CompositeProjectionOptionsStep<?,T> composite
(TriFunction<P1, P2, P3, T> transformer, SearchProjection<P1> projection1, SearchProjection<P2> projection2, SearchProjection<P3> projection3) Deprecated.Use.composite().from( projection1, projection2, projection3 ).as( transformer )
instead.<T> ProjectionFinalStep<T>
constant
(T value) Project to a given constant.Project on the distance from the center to aGeoPoint
field.Project the match to aDocumentReference
.entity()
Project to the entity that was originally indexed.<T> EntityProjectionOptionsStep<?,
T> Project to the entity that was originally indexed.Project to a reference to the entity that was originally indexed.Create a DSL step allowing multiple attempts to apply extensions one after the other, failing only if none of the extensions is supported.<T> T
extension
(SearchProjectionFactoryExtension<T, R, E> extension) Extend the current factory with the given extension, resulting in an extended factory offering different types of projections.default FieldProjectionValueStep<?,
Object> Project to the value of a field in the indexed document, without specifying a type.default <T> FieldProjectionValueStep<?,
T> Project to the value of a field in the indexed document.<T> FieldProjectionValueStep<?,
T> field
(String fieldPath, Class<T> type, ValueConvert convert) Project to the value of a field in the indexed document.field
(String fieldPath, ValueConvert convert) Project to the value of a field in the indexed document, without specifying a type.Project to highlights, i.e.default IdProjectionOptionsStep<?,
Object> id()
Project to the identifier of the referenced entity, i.e.<I> IdProjectionOptionsStep<?,
I> Project to the identifier of the referenced entity, i.e.Starts the definition of an object projection, which will yield one value per object in a given object field, the value being the result of combining multiple given projections (usually on fields within the object field).score()
Project on the score of the hit.toAbsolutePath
(String relativeFieldPath) Create a new projection factory whose root for all paths passed to the DSL will be the given object field.
-
Method Details
-
documentReference
DocumentReferenceProjectionOptionsStep<?> documentReference()Project the match to aDocumentReference
.- Returns:
- A DSL step where the "document reference" projection can be defined in more details.
-
entityReference
EntityReferenceProjectionOptionsStep<?,R> entityReference()Project to a reference to the entity that was originally indexed.Entity references are instances of type
EntityReference
, but some mappers may expose a different type for backwards compatibility reasons.EntityReference
should be favored wherever possible as mapper-specific types will eventually be removed.- Returns:
- A DSL step where the "entity reference" projection can be defined in more details.
-
id
Project to the identifier of the referenced entity, i.e. the value of the property marked as@DocumentId
.- Returns:
- A DSL step where the "id" projection can be defined in more details.
-
id
Project to the identifier of the referenced entity, i.e. the value of the property marked as@DocumentId
.- Type Parameters:
I
- The requested type for returned identifiers.- Parameters:
requestedIdentifierType
- The requested type for returned identifiers. Must be exactly the type of identifiers of the entity types targeted by the search, or a supertype.- Returns:
- A DSL step where the "id" projection can be defined in more details.
- Throws:
SearchException
- if the identifier type doesn't match
-
entity
EntityProjectionOptionsStep<?,E> entity()Project to the entity that was originally indexed.The actual type of the entity depends on the mapper used to create the query and on the indexes targeted by your query: the Hibernate ORM mapper will return a managed entity loaded from the database, for example.
- Returns:
- A DSL step where the "entity" projection can be defined in more details.
-
entity
Project to the entity that was originally indexed.The expected type will be checked against the actual type of the entity, which depends on the mapper used to create the query and on the indexes targeted by your query: the Hibernate ORM mapper will return a managed entity loaded from the database, for example.
- Parameters:
requestedEntityType
- The requested type for returned entities. Must be exactly the type of entities targeted by the search, or a supertype.- Returns:
- A DSL step where the "entity" projection can be defined in more details.
-
field
Project to the value of a field in the indexed document.This method will apply projection converters on data fetched from the backend. See
ValueConvert.YES
.- Type Parameters:
T
- The resulting type of the projection.- Parameters:
fieldPath
- The path to the index field whose value will be extracted.type
- The resulting type of the projection.- Returns:
- A DSL step where the "field" projection can be defined in more details.
-
field
Project to the value of a field in the indexed document.- Type Parameters:
T
- The resulting type of the projection.- Parameters:
fieldPath
- The path to the index field whose value will be extracted.type
- The resulting type of the projection.convert
- Controls how the data fetched from the backend should be converted. SeeValueConvert
.- Returns:
- A DSL step where the "field" projection can be defined in more details.
-
field
Project to the value of a field in the indexed document, without specifying a type.This method will apply projection converters on data fetched from the backend. See
ValueConvert.YES
.- Parameters:
fieldPath
- The path to the index field whose value will be extracted.- Returns:
- A DSL step where the "field" projection can be defined in more details.
-
field
Project to the value of a field in the indexed document, without specifying a type.- Parameters:
fieldPath
- The path to the index field whose value will be extracted.convert
- Controls how the data fetched from the backend should be converted. SeeValueConvert
.- Returns:
- A DSL step where the "field" projection can be defined in more details.
-
score
ScoreProjectionOptionsStep<?> score()Project on the score of the hit.- Returns:
- A DSL step where the "score" projection can be defined in more details.
-
distance
Project on the distance from the center to aGeoPoint
field.- Parameters:
fieldPath
- The path to the index field containing the location to compute the distance from.center
- The center to compute the distance from.- Returns:
- A DSL step where the "distance" projection can be defined in more details.
-
object
Starts the definition of an object projection, which will yield one value per object in a given object field, the value being the result of combining multiple given projections (usually on fields within the object field).Compared to the basic
composite projection
, an object projection is bound to a specific object field, and thus it yields zero, one or many values, as many as there are objects in the targeted object field. Therefore, you must take care of callingCompositeProjectionValueStep.multi()
if the object field is multi-valued.- Parameters:
objectFieldPath
- The path to the object field whose object(s) will be extracted.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
CompositeProjectionInnerStep composite()Starts the definition of a composite projection, which will combine multiple given projections.On contrary to the
object projection
, a composite projection is not bound to a specific object field, and thus it will always yield one and only one value, regardless of whetherCompositeProjectionValueStep.multi()
is called.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
Create a projection that will compose aList
based on the given projections.- Parameters:
projections
- The projections used to populate the list, in order.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
Create a projection that will compose aList
based on the given almost-built projections.- Parameters:
dslFinalSteps
- The final steps in the projection DSL allowing the retrieval ofSearchProjection
s.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
@Deprecated default <T> CompositeProjectionOptionsStep<?,T> composite(Function<List<?>, T> transformer, SearchProjection<?>... projections) Deprecated.Use.composite().from( projections ).asList( transformer )
instead.Create a projection that will compose a custom object based on the given projections.- Type Parameters:
T
- The type of the custom object composing the projected elements.- Parameters:
transformer
- The function that will transform the list of projected elements into a custom object.projections
- The projections used to populate the list, in order.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
@Deprecated default <T> CompositeProjectionOptionsStep<?,T> composite(Function<List<?>, T> transformer, ProjectionFinalStep<?>... dslFinalSteps) Deprecated.Use.composite().from( dslFinalSteps ).asList( transformer )
instead.Create a projection that will compose a custom object based on the given almost-built projections.- Type Parameters:
T
- The type of the custom object composing the projected elements.- Parameters:
transformer
- The function that will transform the projected element into a custom object.dslFinalSteps
- The final steps in the projection DSL allowing the retrieval ofSearchProjection
s.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
@Deprecated default <P,T> CompositeProjectionOptionsStep<?,T> composite(Function<P, T> transformer, SearchProjection<P> projection) Deprecated.Use.composite().from( projection ).as( transformer )
instead.Create a projection that will compose a custom object based on one given projection.- Type Parameters:
P
- The type of the element passed to the transformer.T
- The type of the custom object composing the projected element.- Parameters:
transformer
- The function that will transform the projected element into a custom object.projection
- The original projection used to produce the element passed to the transformer.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
@Deprecated default <P,T> CompositeProjectionOptionsStep<?,T> composite(Function<P, T> transformer, ProjectionFinalStep<P> dslFinalStep) Deprecated.Use.composite().from( dslFinalStep ).as( transformer )
instead.Create a projection that will compose a custom object based on one almost-built projection.- Type Parameters:
P
- The type of the element passed to the transformer.T
- The type of the custom object composing the projected element.- Parameters:
transformer
- The function that will transform the projected element into a custom object.dslFinalStep
- The final step in the projection DSL allowing the retrieval of theSearchProjection
that will be used to produce the element passed to the transformer.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
@Deprecated default <P1,P2, CompositeProjectionOptionsStep<?,T> T> composite(BiFunction<P1, P2, T> transformer, SearchProjection<P1> projection1, SearchProjection<P2> projection2) Deprecated.Use.composite().from( projection1, projection2 ).as( transformer )
instead.Create a projection that will compose a custom object based on two given projections.- Type Parameters:
P1
- The type of the first element passed to the transformer.P2
- The type of the second element passed to the transformer.T
- The type of the custom object composing the projected elements.- Parameters:
transformer
- The function that will transform the projected elements into a custom object.projection1
- The projection used to produce the first element passed to the transformer.projection2
- The projection used to produce the second element passed to the transformer.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
@Deprecated default <P1,P2, CompositeProjectionOptionsStep<?,T> T> composite(BiFunction<P1, P2, T> transformer, ProjectionFinalStep<P1> dslFinalStep1, ProjectionFinalStep<P2> dslFinalStep2) Deprecated.Use.composite().from( dslFinalStep1, dslFinalStep2 ).as( transformer )
instead.Create a projection that will compose a custom object based on two almost-built projections.- Type Parameters:
P1
- The type of the first element passed to the transformer.P2
- The type of the second element passed to the transformer.T
- The type of the custom object composing the projected elements.- Parameters:
transformer
- The function that will transform the projected elements into a custom object.dslFinalStep1
- The final step in the projection DSL allowing the retrieval of theSearchProjection
that will be used to produce the first element passed to the transformer.dslFinalStep2
- The final step in the projection DSL allowing the retrieval of theSearchProjection
that will be used to produce the second element passed to the transformer.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
@Deprecated default <P1,P2, CompositeProjectionOptionsStep<?,P3, T> T> composite(TriFunction<P1, P2, P3, T> transformer, SearchProjection<P1> projection1, SearchProjection<P2> projection2, SearchProjection<P3> projection3) Deprecated.Use.composite().from( projection1, projection2, projection3 ).as( transformer )
instead.Create a projection that will compose a custom object based on three given projections.- Type Parameters:
P1
- The type of the first element passed to the transformer.P2
- The type of the second element passed to the transformer.P3
- The type of the third element passed to the transformer.T
- The type of the custom object composing the projected elements.- Parameters:
transformer
- The function that will transform the projected elements into a custom object.projection1
- The projection used to produce the first element passed to the transformer.projection2
- The projection used to produce the second element passed to the transformer.projection3
- The projection used to produce the third element passed to the transformer.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
composite
@Deprecated default <P1,P2, CompositeProjectionOptionsStep<?,P3, T> T> composite(TriFunction<P1, P2, P3, T> transformer, ProjectionFinalStep<P1> dslFinalStep1, ProjectionFinalStep<P2> dslFinalStep2, ProjectionFinalStep<P3> dslFinalStep3) Deprecated.Use.composite().from( dslFinalStep1, dslFinalStep2, dslFinalStep3 ).as( transformer )
instead.Create a projection that will compose a custom object based on three almost-built projections.- Type Parameters:
P1
- The type of the first element passed to the transformer.P2
- The type of the second element passed to the transformer.P3
- The type of the third element passed to the transformer.T
- The type of the custom object composing the projected elements.- Parameters:
transformer
- The function that will transform the projected elements into a custom object.dslFinalStep1
- The final step in the projection DSL allowing the retrieval of theSearchProjection
that will be used to produce the first element passed to the transformer.dslFinalStep2
- The final step in the projection DSL allowing the retrieval of theSearchProjection
that will be used to produce the second element passed to the transformer.dslFinalStep3
- The final step in the projection DSL allowing the retrieval of theSearchProjection
that will be used to produce the third element passed to the transformer.- Returns:
- A DSL step where the "composite" projection can be defined in more details.
-
constant
Project to a given constant.The projection will return the same value for every single hit.
- Parameters:
value
- The constant value that the projection should return.- Returns:
- A DSL step where the "entity reference" projection can be defined in more details.
-
extension
Extend the current factory with the given extension, resulting in an extended factory offering different types of projections.- Type Parameters:
T
- The type of factory provided by the extension.- Parameters:
extension
- The extension to the projection DSL.- Returns:
- The extended factory.
- Throws:
SearchException
- If the extension cannot be applied (wrong underlying backend, ...).
-
extension
Create a DSL step allowing multiple attempts to apply extensions one after the other, failing only if none of the extensions is supported.If you only need to apply a single extension and fail if it is not supported, use the simpler
extension(SearchProjectionFactoryExtension)
method instead.This method is generic, and you should set the generic type explicitly to the expected projected type, e.g.
.<MyProjectedType>extension()
.- Type Parameters:
T
- The expected projected type.- Returns:
- A DSL step.
-
withRoot
Create a new projection factory whose root for all paths passed to the DSL will be the given object field.This is used to call reusable methods that can apply the same projection on different object fields that have same structure (same sub-fields).
- Parameters:
objectFieldPath
- The path from the current root to an object field that will become the new root.- Returns:
- A new projection factory using the given object field as root.
-
toAbsolutePath
- Parameters:
relativeFieldPath
- The path to a field, relative to theroot
of this factory.- Returns:
- The absolute path of the field, for use in native projections for example. Note the path is returned even if the field doesn't exist.
-
highlight
Project to highlights, i.e. sequences of text that matched the query, extracted from the given field's value.- Parameters:
fieldPath
- The path to the index field whose highlights will be extracted.- Returns:
- A DSL step where the "highlight" projection can be defined in more details.
-
.composite().from( dslFinalStep1, dslFinalStep2 ).as( transformer )
instead.