code: public void close() throws IOException {
      LOG.info("Closing the shard writer, processed " + numForms + " forms");
      try {
        try {
          if (maxNumSegments > 0) {
            writer.optimize(maxNumSegments);
            LOG.info("Optimized the shard into at most " + maxNumSegments
                + " segments");
          }
        } finally {
          writer.close();
          LOG.info("Closed Lucene index writer");
        }
  
        moveFromTempToPerm();
        LOG.info("Moved new index files to " + perm);
  
      } finally {
        dir.close();
        LOG.info("Closed the shard writer");
      }
    }
docs: Close the shard writer. Optimize the Lucene instance of the shard before
  closing if necessary, and copy the files created in the temp directory
  to the permanent directory after closing.
  @throws IOException