Full-Text Search

Since Jmix 3.1

If the application uses the Search add-on, dynamic attributes can be indexed for full-text search. You decide which attributes are searchable in the dynamic model, where the attributes are defined. No Java index definition and no redeploy are needed.

Searchable Attributes

To index an attribute, select the Searchable checkbox in the attribute dialog, or set searchable: true in YAML:

- name: "Customer"
  attributes:
    - name: "taxId"
      javaClass: "java.lang.String"
      length: 20
      searchable: true
      messages:
        en: "Tax ID"

The following attributes can be searchable:

  • java.lang.String attributes;

  • enumeration attributes;

  • single-valued references. A reference is indexed by the instance name of the referenced entity, the same as a static reference.

Calculated and collection attributes cannot be searchable. A model with such an attribute marked as searchable is refused.

The Searchable checkbox is shown only if the Search add-on is in the application. If an index definition of the application already indexes the attribute, for example with the * wildcard, the checkbox is selected and read-only.

Indexed Entities

An entity, static or dynamic, is indexed if at least one of its dynamic attributes is searchable, or if the application has a Java index definition for it. If both exist, the searchable attributes are added to the Java index definition, and the fields that the Java definition already indexes are kept.

When you apply the model, the index definitions are updated, and the index schemas are synchronized according to the jmix.search.index-schema-management-strategy property. Existing rows are not indexed again automatically. To add the values of a new searchable attribute for existing rows, run the enqueueIndexAll operation of the EntityIndexing MBean for the entity.

After that, indexing works the same as for static entities:

  • Creating, changing and deleting an instance of a dynamic entity, or changing the indexed dynamic attributes of a static entity, adds the instance to the indexing queue.

  • If an entity referenced by a dynamic reference is changed or deleted, the entities that refer to it are indexed again.

Searching

Dynamic entities are found in the same way as static ones, with the searchField component and the search API. You can also use the fullTextFilter component in a list view of a dynamic entity. If a search result belongs to an entity that has no detail view, a warning is shown when the user opens it.