code: func (w *IndexWriter) Close() error {
  	assert2(w.pendingCommit == nil,
  		"cannot close: prepareCommit was already called with no corresponding call to commit")
  	// Ensure that only one goroutine actaully gets to do the closing
  	w.commitLock.Lock()
  	defer w.commitLock.Unlock()
  	return w.close(func() (ok bool, err error) {
  		defer func() {
  			if !ok { // be certain to close the index on any error
  				defer recover() // suppress so we keep returning original error
  				w.rollbackInternal()
  			}
  		}()
  		if w.infoStream.IsEnabled("IW") {
  			w.infoStream.Message("IW", "now flush at close")
  		}
  		if err = w.flush(true, true); err != nil {
  			return
  		}
  		w.waitForMerges()
  		if err = w.commitInternal(w.config.MergePolicy()); err != nil {
  			return
  		}
  		return w.rollbackInternal() // ie close, since we just committed
  	})
  }
docs: /*
  Commits all changes to an index, wait for pending merges to complete,
  and closes all associate files.
  
  Note that:
  	1. If you called prepare Commit but failed to call commit, this
  	method will panic and the IndexWriter will not be closed.
  	2. If this method throws any other exception, the IndexWriter will
  	be closed, but changes may have been lost.
  
  Note that this may be a costly operation, so, try to re-use a single
  writer instead of closing and opening a new one. See commit() for
  caveats about write caching done by some IO devices.
  
  NOTE: You must ensure no other threads are still making changes at
  the same time that this method is invoked.
  */