Commits all changes to an index and closes all associated files. 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 {@link #Commit()} for caveats about write caching done by some IO devices.

If an Exception is hit during close, eg due to disk full or some other reason, then both the on-disk index and the internal state of the IndexWriter instance will be consistent. However, the close will not be complete even though part of it (flushing buffered documents) may have succeeded, so the write lock will still be held.

If you can correct the underlying cause (eg free up some disk space) then you can call close() again. Failing that, if you want to force the write lock to be released (dangerous, because you may then lose buffered docs in the IndexWriter instance) then you can do something like this:

            try {
            writer.close();
            } finally {
            if (IndexWriter.isLocked(directory)) {
            IndexWriter.unlock(directory);
            }
            }
            
after which, you must be certain not to use the writer instance anymore.

NOTE: if this method hits an OutOfMemoryError you should immediately close the writer, again. See above for details.

Namespace: Lucene.Net.Index
Assembly: Lucene.Net (in Lucene.Net.dll) Version: 2.9.4.1

Syntax

C#
public virtual void Close()
Visual Basic
Public Overridable Sub Close
Visual C++
public:
virtual void Close()

See Also