本文整理汇总了C#中RandomIndexWriter.DeleteAll方法的典型用法代码示例。如果您正苦于以下问题:C# RandomIndexWriter.DeleteAll方法的具体用法?C# RandomIndexWriter.DeleteAll怎么用?C# RandomIndexWriter.DeleteAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RandomIndexWriter
的用法示例。
在下文中一共展示了RandomIndexWriter.DeleteAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDeleteAllNoDeadLock
public virtual void TestDeleteAllNoDeadLock()
{
Directory dir = NewDirectory();
RandomIndexWriter modifier = new RandomIndexWriter(Random(), dir);
int numThreads = AtLeast(2);
ThreadClass[] threads = new ThreadClass[numThreads];
CountDownLatch latch = new CountDownLatch(1);
CountDownLatch doneLatch = new CountDownLatch(numThreads);
for (int i = 0; i < numThreads; i++)
{
int offset = i;
threads[i] = new ThreadAnonymousInnerClassHelper(this, modifier, latch, doneLatch, offset);
threads[i].Start();
}
latch.countDown();
//Wait for 1 millisecond
while ([email protected](new TimeSpan(0, 0, 0, 0, 1)))
{
modifier.DeleteAll();
if (VERBOSE)
{
Console.WriteLine("del all");
}
}
modifier.DeleteAll();
foreach (ThreadClass thread in threads)
{
thread.Join();
}
modifier.Dispose();
DirectoryReader reader = DirectoryReader.Open(dir);
Assert.AreEqual(reader.MaxDoc, 0);
Assert.AreEqual(reader.NumDocs, 0);
Assert.AreEqual(reader.NumDeletedDocs, 0);
reader.Dispose();
dir.Dispose();
}
示例2: Build
/// <summary>
/// LUCENENET specific
/// Passed in because NewStringField and NewIndexWriterConfig are no
/// longer static.
/// </summary>
private IndexReader Build(Random random, TestIndex index)
{
/* build an index */
Document doc = new Document();
Field idField = NewStringField(random, "id", "", Field.Store.YES);
Field randField = NewStringField(random, "rand", "", Field.Store.YES);
Field bodyField = NewStringField(random, "body", "", Field.Store.NO);
doc.Add(idField);
doc.Add(randField);
doc.Add(bodyField);
RandomIndexWriter writer = new RandomIndexWriter(random, index.Index, NewIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetOpenMode(OpenMode.CREATE).SetMaxBufferedDocs(TestUtil.NextInt(random, 50, 1000)).SetMergePolicy(NewLogMergePolicy()));
TestUtil.ReduceOpenFiles(writer.w);
while (true)
{
int minCount = 0;
int maxCount = 0;
for (int d = MinId; d <= MaxId; d++)
{
idField.StringValue = Pad(d);
int r = index.AllowNegativeRandomInts ? random.Next() : random.Next(int.MaxValue);
if (index.MaxR < r)
{
index.MaxR = r;
maxCount = 1;
}
else if (index.MaxR == r)
{
maxCount++;
}
if (r < index.MinR)
{
index.MinR = r;
minCount = 1;
}
else if (r == index.MinR)
{
minCount++;
}
randField.StringValue = Pad(r);
bodyField.StringValue = "body";
writer.AddDocument(doc);
}
if (minCount == 1 && maxCount == 1)
{
// our subclasses rely on only 1 doc having the min or
// max, so, we loop until we satisfy that. it should be
// exceedingly rare (Yonik calculates 1 in ~429,000)
// times) that this loop requires more than one try:
IndexReader ir = writer.Reader;
writer.Dispose();
return ir;
}
// try again
writer.DeleteAll();
}
}