Annotation Interface JmixEntitySearchIndex
Mapping.
Index mapping can be defined in two ways.
The first one - by using field-mapping annotation. Create one or several methods
and annotate them with one or more field-mapping annotations (e.g. AutoMappedField
).
Such method should fulfil the following requirements:
- With void return type
- With any name
- Without body
- Without parameters
The second one - by building MappingDefinition
directly.
Create one method that fulfils the following requirements:
- With default modifier
- With any name
- With return type -
MappingDefinition
- With Spring beans required for custom user configuration as parameters
- Annotated with
ManualMappingDefinition
MappingDefinition.builder()
within method body to build MappingDefinition
.
Note: if there is definition method with implementation - any field-mapping annotations will be ignored.
Indexable Predicate.
Indexing process can have additional instance-level condition. It can be added by configuring Indexable Predicate. This predicate applies to each entity instance during indexing and defines if it should be indexed or not.
It doesn't apply during deletion.
To configure Indexable Predicate add method that fulfils the following requirements:
- With default modifier
- With any name
- With return type -
Predicate
<TargetEntity>, where 'TargetEntity' is a value ofentity()
parameter of current annotation. Or it just can beObject
- With Spring beans required for predicate logic as parameters
- Annotated with
IndexablePredicate
Note: instance passed to predicate includes only declared indexable properties, others are unfetched. To get access to them you need to reload instance with proper fetch plan within predicate.
Example:
'status' property is not declared as indexable but required for predicate - instance should be reloaded.
@JmixEntitySearchIndex(entity = MyEntity.class) public interface MyEntityIndexDefinition { @AutoMappedField(includeProperties = "name") void mapping(); @IndexablePredicate default Predicate<MyEntity> indexOpenOnlyPredicate(DataManager dataManager) { return (instance) -> { Id<MyEntity> id = Id.of(instance); MyEntity reloadedInstance = dataManager.load(id) .fetchPlanProperties("status") .one(); Status status = reloadedInstance.getStatus(); return Status.OPEN.equals(status); }; } }
-
Required Element Summary
-
Optional Element Summary
-
Element Details
-
entity
Class<?> entityProvides entity that should be indexed using this index definition interface.All properties defined in further field-mapping annotation related to this entity.
- Returns:
- entity class
-
-
-
indexName
String indexNameProvides explicitly defined name of the search index.If it's not set index name will be based on 'searchIndexNamePrefix' property and entity name.
- Returns:
- custom index name
- Default:
- ""
-