Class AbstractIndexer

java.lang.Object
de.cxp.ocs.indexer.AbstractIndexer
All Implemented Interfaces:
FullIndexationService, UpdateIndexService
Direct Known Subclasses:
ElasticsearchIndexer

public abstract class AbstractIndexer extends Object implements FullIndexationService, UpdateIndexService
  • Constructor Details

  • Method Details

    • startImport

      public ImportSession startImport(String indexName, String locale) throws IllegalStateException
      Description copied from interface: FullIndexationService
      Start a new full import. Returns a handle containing meta data, that has to be passed to all following calls.
      Specified by:
      startImport in interface FullIndexationService
      Parameters:
      indexName - index name, that should match the regular expression '[a-z0-9_-]+'
      locale - used for language dependent settings
      Returns:
      ImportSession that should be used for follow up requests to add data to that new index
      Throws:
      IllegalStateException - in case there is already a full-import running for that index.
    • cleanupAbandonedImports

      protected abstract void cleanupAbandonedImports(String indexName, int minAgeSeconds)
    • indexExists

      public abstract boolean indexExists(String indexName)
    • isImportRunning

      public abstract boolean isImportRunning(String indexName)

      Checks if an active import session exists for that index.

      This could either be the full internal or the minimal/final index name.

      Parameters:
      indexName - internal or external index name
      Returns:
    • initNewIndex

      protected abstract String initNewIndex(String indexName, String locale) throws IOException
      Throws:
      IOException
    • add

      public int add(BulkImportData data) throws Exception
      Description copied from interface: FullIndexationService
      Add one or more documents to a running import session.
      Specified by:
      add in interface FullIndexationService
      Parameters:
      data - bulk data which consist of the ImportSession and one or more products that should be added to that index.
      Returns:
      the amount of documents that were successfully added to the index
      Throws:
      Exception - in case import session is invalid
    • addToIndex

      protected abstract int addToIndex(ImportSession session, List<IndexableItem> bulk) throws Exception
      Throws:
      Exception
    • validateSession

      protected abstract void validateSession(ImportSession session) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • done

      public boolean done(ImportSession session) throws Exception
      Description copied from interface: FullIndexationService
      Finishes the import, flushing the new index and (in case there is already an index with the initialized name) replacing the old one.
      Specified by:
      done in interface FullIndexationService
      Parameters:
      session - ImportSession that should be closed.
      Returns:
      true on success, otherwise false
      Throws:
      Exception - if import session is invalid
    • deploy

      protected abstract boolean deploy(ImportSession session)
    • cancel

      public void cancel(ImportSession session)
      Description copied from interface: FullIndexationService
      Cancels import which results in a deletion of the temporary index.
      Specified by:
      cancel in interface FullIndexationService
      Parameters:
      session - ImportSession that contains the information, which index should be dropped.
    • deleteIndex

      protected abstract void deleteIndex(String indexName)
    • _get

      protected abstract Document _get(@NonNull @NonNull String indexName, @NonNull @NonNull String docId)
    • patchDocuments

      public Map<String,UpdateIndexService.Result> patchDocuments(String indexName, List<Document> documents)
      Description copied from interface: UpdateIndexService

      Partial update of an existing document. If the document does not exist, no update will be performed and status 404 is returned.

      In case the document is a master product with variants, the provided master product may only contain the changed values. However if some data at the product variants are updated, all data from all variant products are required, otherwise missing variants won't be there after the update!

      Specified by:
      patchDocuments in interface UpdateIndexService
      Parameters:
      indexName - name of the index that should receive that update
      documents - Full or partial document that carries the data for the update
      Returns:
      Result code, one of UPDATED, NOT_FOUND, NOOP, DISMISSED
    • patchDocument

      public UpdateIndexService.Result patchDocument(String index, Document doc)
    • _patch

      protected abstract UpdateIndexService.Result _patch(String index, IndexableItem indexableItem)
    • putDocuments

      public Map<String,UpdateIndexService.Result> putDocuments(String indexName, Boolean replaceExisting, String langCode, List<Document> documents)
      Put documents into existing index. langCode is ignored.
      Specified by:
      putDocuments in interface UpdateIndexService
      Parameters:
      indexName - name of existing index
      replaceExisting - set to true, if an existing document with the same ID should be replaced.
      langCode - ignored
      documents - list of documents that should be put into index
      Returns:
      map of results with one entry per given document, with the document IDs as key
    • putDocuments

      public Map<String,UpdateIndexService.Result> putDocuments(String indexName, Boolean replaceExisting, List<Document> documents)
    • putDocument

      public UpdateIndexService.Result putDocument(String indexName, Boolean replaceExisting, Document doc)
    • _put

      protected abstract UpdateIndexService.Result _put(String indexName, Boolean replaceExisting, IndexableItem indexableItem)