Lucene.Net.Index.IndexReader.Reopen C# (CSharp) Method

Reopen() public method

Refreshes an IndexReader if the index has changed since this instance was (re)opened.

Opening an IndexReader is an expensive operation. This method can be used to refresh an existing IndexReader to reduce these costs. This method tries to only load segments that have changed or were created after the IndexReader was (re)opened.

If the index has not changed since this instance was (re)opened, then this call is a NOOP and returns this instance. Otherwise, a new instance is returned. The old instance is not closed and remains usable.

If the reader is reopened, even though they share resources internally, it's safe to make changes (deletions, norms) with the new reader. All shared mutable state obeys "copy on write" semantics to ensure the changes are not seen by other readers.

You can determine whether a reader was actually reopened by comparing the old instance with the instance returned by this method: IndexReader reader = ... ... IndexReader newReader = r.reopen(); if (newReader != reader) { ... // reader was reopened reader.close(); } reader = newReader; ... Be sure to synchronize that code so that other threads, if present, can never use reader after it has been closed and before it's switched to newReader.

NOTE: If this reader is a near real-time reader (obtained from IndexWriter.GetReader(), reopen() will simply call writer.getReader() again for you, though this may change in the future.

public Reopen ( ) : IndexReader
return IndexReader
		public virtual IndexReader Reopen()
		{
			lock (this)
			{
				throw new NotSupportedException("This reader does not support reopen().");
			}
		}
		

Same methods

IndexReader::Reopen ( IndexCommit commit ) : IndexReader
IndexReader::Reopen ( bool openReadOnly ) : IndexReader

Usage Example

 private static IndexReader RefreshReader(IndexReader reader)
 {
     IndexReader oldReader = reader;
     reader = reader.Reopen();
     if (reader != oldReader)
     {
         oldReader.Close();
     }
     return reader;
 }
All Usage Examples Of Lucene.Net.Index.IndexReader::Reopen