Method Dispose
Dispose()
Commits all changes to an index, waits for pending merges to complete, and closes all associated files.
This is a "slow graceful shutdown" which may take a long time especially if a big merge is pending: If you only want to close resources use Rollback(). If you only want to commit pending changes and close resources see Dispose(Boolean).
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
If you can correct the underlying cause (eg free up some disk space) then you can call Dispose() 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.Dispose();
}
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
Declaration
public 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
NOTE: it is dangerous to always call
Dispose(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 |