Class SearchIndexer

java.lang.Object
com.codename1.backend.search.SearchIndexer
All Implemented Interfaces:
com.codename1.impl.orm.CommitObserver

public final class SearchIndexer extends Object implements com.codename1.impl.orm.CommitObserver

Keeps the index of each @Searchable entity in step with what a session committed. The ORM installs one on every session it opens inside a server; an application does not create it.

The index is written after the data is durable, so a failure here cannot undo the commit: it is logged, and the entity is indexed again the next time it is written.

  • Field Summary

    Fields inherited from interface com.codename1.impl.orm.CommitObserver

    PERSISTED, REMOVED, UPDATED
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    committed(com.codename1.impl.orm.EntityModel<?> model, Object entity, int event)
    entity of model was written with event by a transaction that has committed.
    static String
    documentId(com.codename1.impl.orm.EntityModel model, Object id)
    The search document id of the entity whose identifier is id (what Session.find takes): its columns joined by :.
    The indexer for a session opened by the calling thread, or null outside a server, where there is no search engine to write to.
    to(SearchEngine engine)
    An indexer writing to engine, for a session opened outside a server (SessionImpl.setCommitObserver).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • forServer

      public static SearchIndexer forServer()
      The indexer for a session opened by the calling thread, or null outside a server, where there is no search engine to write to.
    • to

      public static SearchIndexer to(SearchEngine engine)
      An indexer writing to engine, for a session opened outside a server (SessionImpl.setCommitObserver). The caller keeps ownership of it.
    • committed

      public void committed(com.codename1.impl.orm.EntityModel<?> model, Object entity, int event)
      Description copied from interface: com.codename1.impl.orm.CommitObserver
      entity of model was written with event by a transaction that has committed. The data is already durable: an exception thrown here does not stop the other writes being delivered, and reaches the caller of commitTransaction only after the commit, with the session intact.
      Specified by:
      committed in interface com.codename1.impl.orm.CommitObserver
    • documentId

      public static String documentId(com.codename1.impl.orm.EntityModel model, Object id)
      The search document id of the entity whose identifier is id (what Session.find takes): its columns joined by :. ASCII letters, digits, - and _ stand as they are; every other character, . and : included, is written . and four hex digits. So 42 and a UUID are unchanged, a@b.com is a.0040b.002ecom, no two keys share an id, and every id fits the alphabet Elasticsearch's document paths accept.