code: func (w *IndexWriter) flush(triggerMerge bool, applyAllDeletes bool) error {
  	// NOTE: this method cannot be sync'd because
  	// maybeMerge() in turn calls mergeScheduler.merge which
  	// in turn can take a long time to run and we don't want
  	// to hold the lock for that.  In the case of
  	// ConcurrentMergeScheduler this can lead to deadlock
  	// when it stalls due to too many running merges.
  
  	// We can be called during close, when closing==true, so we must pass false to ensureOpen:
  	w.ClosingControl.ensureOpen(false)
  	ok, err := w.doFlush(applyAllDeletes)
  	if err != nil {
  		return err
  	}
  	if ok && triggerMerge {
  		return w.maybeMerge(w.config.MergePolicy(), MERGE_TRIGGER_FULL_FLUSH, UNBOUNDED_MAX_MERGE_SEGMENTS)
  	}
  	return nil
  }
docs: /*
  Flush all in-memory buffered updates (adds and deletes) to the
  Directory.
  */