本文整理汇总了C#中Lucene.Net.Index.IndexReader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# IndexReader.Close方法的具体用法?C# IndexReader.Close怎么用?C# IndexReader.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexReader
的用法示例。
在下文中一共展示了IndexReader.Close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloseReader
public void CloseReader(IndexReader reader)
{
try
{
reader.Close();
}
catch (System.IO.IOException ex)
{
//TODO: extract subReaders and close each one individually
ReaderProviderHelper.Clean(reader);
new SearchException("Unable to close multiReader", ex);
}
}
示例2: TestFieldNonExistent
public void TestFieldNonExistent()
{
try
{
indexReader = IndexReader.Open(store, true);
ld = new LuceneDictionary(indexReader, "nonexistent_field");
it = ld.GetWordsIterator();
AssertFalse("More elements than expected", it.HasNext());
AssertTrue("Nonexistent element is really null", it.Next() == null);
}
finally
{
if (indexReader != null) { indexReader.Close(); }
}
}
示例3: ReplaceActiveReader
private IndexReader ReplaceActiveReader(IndexReader outOfDateReader, object directoryProviderLock,
IDirectoryProvider directoryProvider, IndexReader[] readers)
{
bool trace = log.IsInfoEnabled;
IndexReader oldReader;
bool closeOldReader = false;
bool closeOutOfDateReader = false;
IndexReader reader;
/**
* Since out of lock protection, can have multiple readers created in //
* not worse than NotShared and limit the locking time, hence scalability
*/
try
{
reader = IndexReader.Open(directoryProvider.Directory);
}
catch (IOException e)
{
throw new SearchException("Unable to open Lucene IndexReader", e);
}
lock (directoryProviderLock)
{
// Since not protected by a lock, other ones can have been added
oldReader = activeSearchIndexReaders[directoryProvider] = reader;
lock (semaphoreIndexReaderLock)
{
searchIndexReaderSemaphores[reader] = new ReaderData(1, directoryProvider);
if (trace) log.Info("Semaphore: 1 for " + reader);
if (outOfDateReader != null)
{
ReaderData readerData;
searchIndexReaderSemaphores.TryGetValue(outOfDateReader, out readerData);
if (readerData == null)
{
closeOutOfDateReader = false; //already removed by another prevous thread
}
else if (readerData.Semaphore == 0)
{
searchIndexReaderSemaphores.Remove(outOfDateReader);
closeOutOfDateReader = true;
}
else
{
closeOutOfDateReader = false;
}
}
if (oldReader != null && oldReader != outOfDateReader)
{
ReaderData readerData = searchIndexReaderSemaphores[oldReader];
if (readerData == null)
{
log.Warn("Semaphore should not be null");
closeOldReader = true; //TODO should be true or false?
}
else if (readerData.Semaphore == 0)
{
searchIndexReaderSemaphores.Remove(oldReader);
closeOldReader = true;
}
else
{
closeOldReader = false;
}
}
}
}
if (closeOutOfDateReader)
{
if (trace) log.Info("Closing out of date IndexReader " + outOfDateReader);
try
{
outOfDateReader.Close();
}
catch (IOException e)
{
ReaderProviderHelper.Clean(readers);
throw new SearchException("Unable to close Lucene IndexReader", e);
}
}
if (closeOldReader)
{
if (trace) log.Info("Closing old IndexReader " + oldReader);
try
{
oldReader.Close();
}
catch (IOException e)
{
ReaderProviderHelper.Clean(readers);
throw new SearchException("Unable to close Lucene IndexReader", e);
}
}
return reader;
}
示例4: CloseInternalReader
private void CloseInternalReader(bool trace, IndexReader subReader, bool finalClose)
{
ReaderData readerData;
// TODO: can we avoid the lock?
lock (semaphoreIndexReaderLock)
{
readerData = searchIndexReaderSemaphores[subReader];
}
if (readerData == null)
{
log.Error("Trying to close a Lucene IndexReader not present: " + subReader.Directory());
// TODO: Should we try to close?
return;
}
// Acquire the locks in the same order as everywhere else
object directoryProviderLock = perDirectoryProviderManipulationLocks[readerData.Provider];
bool closeReader = false;
lock (directoryProviderLock)
{
IndexReader reader;
bool isActive = activeSearchIndexReaders.TryGetValue(readerData.Provider, out reader)
&& reader == subReader;
if (trace) log.Info("IndexReader not active: " + subReader);
lock (semaphoreIndexReaderLock)
{
readerData = searchIndexReaderSemaphores[subReader];
if (readerData == null)
{
log.Error("Trying to close a Lucene IndexReader not present: " + subReader.Directory());
// TODO: Should we try to close?
return;
}
//final close, the semaphore should be at 0 already
if (!finalClose)
{
readerData.Semaphore--;
if (trace)
log.Info("Semaphore decreased to: " + readerData.Semaphore + " for " + subReader);
}
if (readerData.Semaphore < 0)
log.Error("Semaphore negative: " + subReader.Directory());
if (!isActive && readerData.Semaphore == 0)
{
searchIndexReaderSemaphores.Remove(subReader);
closeReader = true;
}
else
closeReader = false;
}
}
if (closeReader)
{
if (trace) log.Info("Closing IndexReader: " + subReader);
try
{
subReader.Close();
}
catch (IOException e)
{
log.Warn("Unable to close Lucene IndexReader", e);
}
}
}
示例5: TestFieldAaa
public void TestFieldAaa()
{
try
{
indexReader = IndexReader.Open(store);
ld = new LuceneDictionary(indexReader, "aaa");
it = ld.GetWordsIterator();
AssertTrue("First element doesn't exist.", it.HasNext());
AssertTrue("First element isn't correct", it.Next().Equals("foo"));
AssertFalse("More elements than expected", it.HasNext());
AssertTrue("Nonexistent element is really null", it.Next() == null);
}
finally
{
if (indexReader != null) { indexReader.Close(); }
}
}
示例6: TestSpellchecker
public void TestSpellchecker()
{
SpellChecker.Net.Search.Spell.SpellChecker sc = new SpellChecker.Net.Search.Spell.SpellChecker(new RAMDirectory());
indexReader = IndexReader.Open(store);
sc.IndexDictionary(new LuceneDictionary(indexReader, "contents"));
String[] suggestions = sc.SuggestSimilar("Tam", 1);
AssertEquals(1, suggestions.Length);
AssertEquals("Tom", suggestions[0]);
suggestions = sc.SuggestSimilar("Jarry", 1);
AssertEquals(1, suggestions.Length);
AssertEquals("Jerry", suggestions[0]);
indexReader.Close();
}
示例7: TestFieldContents_2
public void TestFieldContents_2()
{
try
{
indexReader = IndexReader.Open(store);
ld = new LuceneDictionary(indexReader, "contents");
it = ld.GetWordsIterator();
// hasNext() should have no side effects //{{DIGY}} But has. Need a fix?
//AssertTrue("First element isn't were it should be.", it.HasNext());
//AssertTrue("First element isn't were it should be.", it.HasNext());
//AssertTrue("First element isn't were it should be.", it.HasNext());
// just iterate through words
AssertTrue("First element isn't correct", it.Next().Equals("Jerry"));
AssertTrue("Second element isn't correct", it.Next().Equals("Tom"));
AssertTrue("Nonexistent element is really null", it.Next() == null);
// hasNext() should still have no side effects ...
AssertFalse("There should be any more elements", it.HasNext());
AssertFalse("There should be any more elements", it.HasNext());
AssertFalse("There should be any more elements", it.HasNext());
// .. and there are really no more words
AssertTrue("Nonexistent element is really null", it.Next() == null);
AssertTrue("Nonexistent element is really null", it.Next() == null);
AssertTrue("Nonexistent element is really null", it.Next() == null);
}
finally
{
if (indexReader != null) { indexReader.Close(); }
}
}
示例8: TestFieldContents_1
public void TestFieldContents_1()
{
try
{
indexReader = IndexReader.Open(store);
ld = new LuceneDictionary(indexReader, "contents");
it = ld.GetWordsIterator();
AssertTrue("First element doesn't exist.", it.HasNext());
AssertTrue("First element isn't correct", it.Next().Equals("Jerry"));
AssertTrue("Second element doesn't exist.", it.HasNext());
AssertTrue("Second element isn't correct", it.Next().Equals("Tom"));
AssertFalse("More elements than expected", it.HasNext());
AssertTrue("Nonexistent element is really null", it.Next() == null);
ld = new LuceneDictionary(indexReader, "contents");
it = ld.GetWordsIterator();
int counter = 2;
while (it.HasNext())
{
it.Next();
counter--;
}
AssertTrue("Number of words incorrect", counter == 0);
}
finally
{
if (indexReader != null) { indexReader.Close(); }
}
}
示例9: CloseReader
// Special function to permanently remove this reader
// Called when StaticQueryables need to unload
static internal void CloseReader (IndexReader reader)
{
lock (reader_rav_map) {
ReaderAndVersion rav = (ReaderAndVersion) reader_rav_map [reader];
if (rav != null) {
rav.Refcount --; // Remove one extra refcount that was added to keep the reader opened
UnrefReaderAndVersion_Unlocked (rav);
} else
reader.Close ();
}
}
示例10: ReleaseReader
static public void ReleaseReader (IndexReader reader)
{
lock (reader_rav_map) {
ReaderAndVersion rav = (ReaderAndVersion) reader_rav_map [reader];
if (rav != null)
UnrefReaderAndVersion_Unlocked (rav);
else
reader.Close ();
}
}
示例11: CloseIndexReader
private void CloseIndexReader(IndexReader myReader)
{
myReader.Close();
myReader.Dispose();
}