/** Check if time to commit, if so, run commit. Then run search if search timer is also set. */
  void checkRunCommitSearch() {
    if (commitIndex) {
      logger.log(Level.INFO, "Commiting index");
      commit();
      commitIndex = false;

      // after commit, check if time to run searcher
      // NOTE commit/searcher timings don't need to align
      // in worst case, we will run search next time after commit timer goes off, or at the end of
      // ingest
      if (searcherDone && runSearcher) {
        // start search if previous not running
        if (keywords != null && !keywords.isEmpty()) {
          currentSearcher = new Searcher(keywords);
          currentSearcher.execute(); // searcher will stop timer and restart timer when done
        }
      }
    }
  }
  /**
   * After all files are ingested, execute final index commit and final search Cleanup resources,
   * threads, timers
   */
  @Override
  public void complete() {
    if (initialized == false) {
      return;
    }

    // logger.log(Level.INFO, "complete()");
    commitTimer.stop();

    // handle case if previous search running
    // cancel it, will re-run after final commit
    // note: cancellation of Searcher worker is graceful (between keywords)
    if (currentSearcher != null) {
      currentSearcher.cancel(false);
    }

    // cancel searcher timer, ensure unwanted searcher does not start
    // before we start the final one
    if (searchTimer.isRunning()) {
      searchTimer.stop();
    }
    runSearcher = false;

    logger.log(Level.INFO, "Running final index commit and search");
    // final commit
    commit();

    postIndexSummary();

    // run one last search as there are probably some new files committed
    if (keywords != null && !keywords.isEmpty() && processedFiles == true) {
      finalSearcher = new Searcher(keywords, true); // final searcher run
      finalSearcher.execute();
    } else {
      finalSearcherDone = true;
      managerProxy.postMessage(
          IngestMessage.createMessage(++messageID, MessageType.INFO, this, "Completed"));
    }

    // postSummary();
  }