Annotation Interface JmixEntitySearchIndex


@Target(TYPE) @Retention(RUNTIME) public @interface JmixEntitySearchIndex
Annotation to mark index definition interfaces.

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:

Use 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 of entity() parameter of current annotation. Or it just can be Object
  • With Spring beans required for predicate logic as parameters
  • Annotated with IndexablePredicate
Create and return your predicate within method body.

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

    Required Elements
    Modifier and Type
    Required Element
    Description
    Provides entity that should be indexed using this index definition interface.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Provides explicitly defined name of the search index.
  • Element Details

    • entity

      Class<?> entity
      Provides 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 indexName
      Provides 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:
      ""