本文整理汇总了C#中Lucene.Net.Index.IndexReader.Reopen方法的典型用法代码示例。如果您正苦于以下问题:C# IndexReader.Reopen方法的具体用法?C# IndexReader.Reopen怎么用?C# IndexReader.Reopen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexReader
的用法示例。
在下文中一共展示了IndexReader.Reopen方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefreshReader
private static IndexReader RefreshReader(IndexReader reader)
{
IndexReader oldReader = reader;
reader = reader.Reopen();
if (reader != oldReader)
{
oldReader.Close();
}
return reader;
}
示例2: ValidateSearcher
private void ValidateSearcher(bool forceReopen)
{
EnsureIndex();
if (!forceReopen)
{
if (_reader == null)
{
lock (_locker)
{
//double check
if (_reader == null)
{
try
{
//get a reader - could be NRT or based on directly depending on how this was constructed
_reader = _nrtWriter == null
? OpenNewReader()
: _nrtWriter.GetReader();
_searcher = new IndexSearcher(_reader);
}
catch (IOException ex)
{
throw new ApplicationException("Could not create an index searcher with the supplied lucene directory", ex);
}
}
}
}
else
{
switch (_reader.GetReaderStatus())
{
case ReaderStatus.Current:
break;
case ReaderStatus.Closed:
lock (_locker)
{
//get a reader - could be NRT or based on directly depending on how this was constructed
_reader = _nrtWriter == null
? OpenNewReader()
: _nrtWriter.GetReader();
_searcher = new IndexSearcher(_reader);
}
break;
case ReaderStatus.NotCurrent:
lock (_locker)
{
//yes, this is actually the way the Lucene wants you to work...
//normally, i would have thought just calling Reopen() on the underlying reader would suffice... but it doesn't.
//here's references:
// http://stackoverflow.com/questions/1323779/lucene-indexreader-reopen-doesnt-seem-to-work-correctly
// http://gist.github.com/173978
//Also note that when a new reader is returned from Reopen() the old reader is not actually closed -
// but more importantly the old reader might still be in use from another thread! So we can't just
// close it here because that would cause a YSOD: Lucene.Net.Store.AlreadyClosedException: this IndexReader is closed
// since another thread might be using it. I'm 'hoping' that the GC will just take care of the left over reader's that might
// be currently being used in a search, otherwise there's really no way to now when it's safe to close the reader. A reader is
// IDisposable so I'm pretty sure the GC will do it's thing since there won't be any refs to it once it is done using it.
var newReader = _reader.Reopen();
if (newReader != _reader)
{
//if it's changed, then re-assign, note: the above, before we used to close the old one here
// but that will cause problems since the old reader might be in use on another thread.
_reader = newReader;
_searcher = new IndexSearcher(_reader);
}
}
break;
}
}
}
else
{
if (_reader != null)
{
lock (_locker)
{
//double check
if (_reader != null)
{
try
{
_searcher.Close();
_reader.Close();
}
catch (IOException ex)
{
//this will happen if it's already closed ( i think )
Trace.TraceError("Examine: error occurred closing index searcher. {0}", ex);
}
finally
{
//set to null in case another call to this method has passed the first lock and is checking for null
_searcher = null;
//.........这里部分代码省略.........
示例3: RefreshReader
internal virtual ReaderCouple RefreshReader(IndexReader reader, TestReopen test, int modify, bool hasChanges)
{
lock (createReaderMutex)
{
IndexReader r = null;
if (test != null)
{
test.ModifyIndex(modify);
r = test.OpenReader();
}
IndexReader refreshed = null;
try
{
refreshed = reader.Reopen();
}
finally
{
if (refreshed == null && r != null)
{
// Hit exception -- close opened reader
r.Close();
}
}
if (hasChanges)
{
if (refreshed == reader)
{
Assert.Fail("No new IndexReader instance created during refresh.");
}
}
else
{
if (refreshed != reader)
{
Assert.Fail("New IndexReader instance created during refresh even though index had no changes.");
}
}
return new ReaderCouple(r, refreshed);
}
}
示例4: RefreshReader
private ReaderCouple RefreshReader(IndexReader reader, TestReopen_Renamed_Class test, int modify, bool hasChanges)
{
lock (createReaderMutex)
{
IndexReader r = null;
if (test != null)
{
test.ModifyIndex(modify);
r = test.OpenReader();
}
IndexReader refreshed = reader.Reopen();
if (hasChanges)
{
if (refreshed == reader)
{
Assert.Fail("No new IndexReader instance created during refresh.");
}
}
else
{
if (refreshed != reader)
{
Assert.Fail("New IndexReader instance created during refresh even though index had no changes.");
}
}
return new ReaderCouple(r, refreshed);
}
}