本文整理汇总了C#中Lucene.Net.Store.RAMDirectory.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Store.RAMDirectory.Dispose方法的具体用法?C# Lucene.Net.Store.RAMDirectory.Dispose怎么用?C# Lucene.Net.Store.RAMDirectory.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Store.RAMDirectory
的用法示例。
在下文中一共展示了Lucene.Net.Store.RAMDirectory.Dispose方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCustomMergeScheduler
public void TestCustomMergeScheduler()
{
// we don't really need to execute anything, just to make sure the custom MS
// compiles. But ensure that it can be used as well, e.g., no other hidden
// dependencies or something. Therefore, don't use any random API !
Directory dir = new RAMDirectory();
IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
conf.SetMergeScheduler(new ReportingMergeScheduler());
IndexWriter writer = new IndexWriter(dir, conf);
writer.AddDocument(new Document());
writer.Commit(); // trigger flush
writer.AddDocument(new Document());
writer.Commit(); // trigger flush
writer.ForceMerge(1);
writer.Dispose();
dir.Dispose();
}
示例2: TestOpenIfChangedAndRefCount
public virtual void TestOpenIfChangedAndRefCount()
{
Directory dir = new RAMDirectory(); // no need for random directories here
var taxoWriter = new DirectoryTaxonomyWriter(dir);
taxoWriter.AddCategory(new FacetLabel("a"));
taxoWriter.Commit();
var taxoReader = new DirectoryTaxonomyReader(dir);
Assert.AreEqual(1, taxoReader.RefCount, "wrong refCount");
taxoReader.IncRef();
Assert.AreEqual(2, taxoReader.RefCount, "wrong refCount");
taxoWriter.AddCategory(new FacetLabel("a", "b"));
taxoWriter.Commit();
var newtr = TaxonomyReader.OpenIfChanged(taxoReader);
Assert.NotNull(newtr);
taxoReader.Dispose();
taxoReader = newtr;
Assert.AreEqual(1, taxoReader.RefCount, "wrong refCount");
taxoWriter.Dispose();
taxoReader.Dispose();
dir.Dispose();
}
示例3: TestZeroPosIncr
public virtual void TestZeroPosIncr()
{
Directory dir = new RAMDirectory();
Token[] tokens = new Token[3];
tokens[0] = new Token();
tokens[0].Append("a");
tokens[0].PositionIncrement = 1;
tokens[1] = new Token();
tokens[1].Append("b");
tokens[1].PositionIncrement = 0;
tokens[2] = new Token();
tokens[2].Append("c");
tokens[2].PositionIncrement = 0;
RandomIndexWriter writer = new RandomIndexWriter(Random(), dir);
Document doc = new Document();
doc.Add(new TextField("field", new CannedTokenStream(tokens)));
writer.AddDocument(doc);
doc = new Document();
doc.Add(new TextField("field", new CannedTokenStream(tokens)));
writer.AddDocument(doc);
IndexReader r = writer.Reader;
writer.Dispose();
IndexSearcher s = NewSearcher(r);
MultiPhraseQuery mpq = new MultiPhraseQuery();
//mpq.setSlop(1);
// NOTE: not great that if we do the else clause here we
// get different scores! MultiPhraseQuery counts that
// phrase as occurring twice per doc (it should be 1, I
// think?). this is because MultipleTermPositions is able to
// return the same position more than once (0, in this
// case):
if (true)
{
mpq.Add(new Term[] { new Term("field", "b"), new Term("field", "c") }, 0);
mpq.Add(new Term[] { new Term("field", "a") }, 0);
}
else
{
mpq.Add(new Term[] { new Term("field", "a") }, 0);
mpq.Add(new Term[] { new Term("field", "b"), new Term("field", "c") }, 0);
}
TopDocs hits = s.Search(mpq, 2);
Assert.AreEqual(2, hits.TotalHits);
Assert.AreEqual(hits.ScoreDocs[0].Score, hits.ScoreDocs[1].Score, 1e-5);
/*
for(int hit=0;hit<hits.TotalHits;hit++) {
ScoreDoc sd = hits.ScoreDocs[hit];
System.out.println(" hit doc=" + sd.Doc + " score=" + sd.Score);
}
*/
r.Dispose();
dir.Dispose();
}
示例4: TestWriterLock
public virtual void TestWriterLock()
{
// native fslock impl gets angry if we use it, so use RAMDirectory explicitly.
var indexDir = new RAMDirectory();
var tw = new DirectoryTaxonomyWriter(indexDir);
tw.AddCategory(new FacetLabel("hi", "there"));
tw.Commit();
// we deliberately not close the write now, and keep it open and
// locked.
// Verify that the writer worked:
var tr = new DirectoryTaxonomyReader(indexDir);
Assert.AreEqual(2, tr.GetOrdinal(new FacetLabel("hi", "there")));
// Try to open a second writer, with the first one locking the directory.
// We expect to get a LockObtainFailedException.
try
{
Assert.Null(new DirectoryTaxonomyWriter(indexDir));
Fail("should have failed to write in locked directory");
}
catch (LockObtainFailedException)
{
// this is what we expect to happen.
}
// Remove the lock, and now the open should succeed, and we can
// write to the new writer.
DirectoryTaxonomyWriter.Unlock(indexDir);
var tw2 = new DirectoryTaxonomyWriter(indexDir);
tw2.AddCategory(new FacetLabel("hey"));
tw2.Dispose();
// See that the writer indeed wrote:
var newtr = TaxonomyReader.OpenIfChanged(tr);
Assert.NotNull(newtr);
tr.Dispose();
tr = newtr;
Assert.AreEqual(3, tr.GetOrdinal(new FacetLabel("hey")));
tr.Dispose();
tw.Dispose();
indexDir.Dispose();
}
示例5: TestRawIndexInputRead
public virtual void TestRawIndexInputRead()
{
Random random = Random();
RAMDirectory dir = new RAMDirectory();
IndexOutput os = dir.CreateOutput("foo", NewIOContext(random));
os.WriteBytes(READ_TEST_BYTES, READ_TEST_BYTES.Length);
os.Dispose();
IndexInput @is = dir.OpenInput("foo", NewIOContext(random));
CheckReads(@is, typeof(IOException));
@is.Dispose();
os = dir.CreateOutput("bar", NewIOContext(random));
os.WriteBytes(RANDOM_TEST_BYTES, RANDOM_TEST_BYTES.Length);
os.Dispose();
@is = dir.OpenInput("bar", NewIOContext(random));
CheckRandomReads(@is);
@is.Dispose();
dir.Dispose();
}