Method Dispose
Dispose()
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 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.
Declaration
public virtual void Dispose()
Dispose(Boolean)
Closes the index with or without waiting for currently running merges to finish. This is only meaningful when using a MergeScheduler that runs merges in background threads.
NOTE: if this method hits an OutOfMemoryError you should immediately close the writer, again. See above for details.
NOTE: it is dangerous to always call close(false), especially when IndexWriter is not open for very long, because this can result in "merge starvation" whereby long merges will never have a chance to finish. This will cause too many segments in your index over time.
Declaration
public virtual void Dispose(bool waitForMerges)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | waitForMerges | if true, this call will block until all merges complete; else, it will ask all running merges to abort, wait until those merges have finished (which should be at most a few seconds), and then return. |
Dispose(Boolean, Boolean)
Declaration
protected virtual void Dispose(bool disposing, bool waitForMerges)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | |
System.Boolean | waitForMerges |