Interface AlternativeBinder
-
- All Superinterfaces:
TypeBinder
@Incubating public interface AlternativeBinder extends TypeBinder
The binder that sets upAlternativeValueBridge
s.Alternative field bridges solve the problem of mapping one property to multiple fields depending on the value of another property.
One use case is when an entity has text properties whose content is in a different language depending on the value of another property, say
language
. In that case, you probably want to analyze the text differently depending on the language. This binder solves the problem this way:- at bootstrap, declare one index field per language (
title_en
,title_fr
, etc.), assigning a different analyzer to each field; - at runtime, put the content of the text property in a different field based on the language.
In order to use this binder, you will need to:
- annotate a property with
AlternativeDiscriminator
(e.g. thelanguage
property) - implement an
AlternativeBinderDelegate
that will declare the index fields (e.g. one field per language) and create anAlternativeValueBridge
. This bridge is responsible for passing the property value to the relevant field at runtime - apply the
AlternativeBinder
to the type hosting the properties (e.g. the type declaring thelanguage
property and the multi-language text properties). Generally you will want to create your own annotation for that.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static AlternativeDiscriminatorBinder
alternativeDiscriminator()
AlternativeBinder
alternativeId(String id)
static <D,P>
AlternativeBindercreate(Class<D> discriminatorType, String fieldValueSourcePropertyName, Class<P> fieldValueSourcePropertyType, BeanReference<? extends AlternativeBinderDelegate<D,P>> delegateRef)
-
Methods inherited from interface org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.TypeBinder
bind
-
-
-
-
Method Detail
-
alternativeId
AlternativeBinder alternativeId(String id)
- Parameters:
id
- The identifier of the alternative. This is used to differentiate between multiple alternative discriminators:assign an id when building each discriminator marker
, then select the same id here.- Returns:
this
, for method chaining.
-
create
static <D,P> AlternativeBinder create(Class<D> discriminatorType, String fieldValueSourcePropertyName, Class<P> fieldValueSourcePropertyType, BeanReference<? extends AlternativeBinderDelegate<D,P>> delegateRef)
- Type Parameters:
D
- The expected type of alternative discriminator values.P
- The expected type of the field value source.- Parameters:
discriminatorType
- The expected type of alternative discriminator values. The alternative discriminator is designated through thealternativeDiscriminator()
marker.fieldValueSourcePropertyName
- The expected type of the field value source, i.e. the property bound to a different field based on the discriminator.fieldValueSourcePropertyType
- The expected type of the field value source.delegateRef
- A reference to theAlternativeBinderDelegate
, responsible for binding one field per alternative and creating anAlternativeValueBridge
.- Returns:
- An
AlternativeBinder
.
-
alternativeDiscriminator
static AlternativeDiscriminatorBinder alternativeDiscriminator()
- Returns:
- A
MarkerBinder
for the alternative discriminator, to be applied on a property. - See Also:
LatitudeLongitudeMarkerBinder
-
-