本文整理汇总了C#中Lucene.Net.Store.RAMDirectory.FileModified方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Store.RAMDirectory.FileModified方法的具体用法?C# Lucene.Net.Store.RAMDirectory.FileModified怎么用?C# Lucene.Net.Store.RAMDirectory.FileModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Store.RAMDirectory
的用法示例。
在下文中一共展示了Lucene.Net.Store.RAMDirectory.FileModified方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestExpirationTimeDeletionPolicy
public virtual void TestExpirationTimeDeletionPolicy()
{
double SECONDS = 2.0;
bool autoCommit = false;
bool useCompoundFile = true;
Directory dir = new RAMDirectory();
ExpirationTimeDeletionPolicy policy = new ExpirationTimeDeletionPolicy(this, dir, SECONDS);
IndexWriter writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), true, policy);
writer.SetUseCompoundFile(useCompoundFile);
writer.Close();
long lastDeleteTime = 0;
for (int i = 0; i < 7; i++)
{
// Record last time when writer performed deletes of
// past commits
lastDeleteTime = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
writer = new IndexWriter(dir, autoCommit, new WhitespaceAnalyzer(), false, policy);
writer.SetUseCompoundFile(useCompoundFile);
for (int j = 0; j < 17; j++)
{
AddDoc(writer);
}
writer.Close();
// Make sure to sleep long enough so that some commit
// points will be deleted:
System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * (int) (1000.0 * (SECONDS / 5.0))));
}
// First, make sure the policy in fact deleted something:
Assert.IsTrue(policy.numDelete > 0, "no commits were deleted");
// Then simplistic check: just verify that the
// segments_N's that still exist are in fact within SECONDS
// seconds of the last one's mod time, and, that I can
// open a reader on each:
long gen = SegmentInfos.GetCurrentSegmentGeneration(dir);
System.String fileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen);
dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
while (gen > 0)
{
try
{
IndexReader reader = IndexReader.Open(dir);
reader.Close();
fileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen);
long modTime = dir.FileModified(fileName);
Assert.IsTrue(lastDeleteTime - modTime <= (SECONDS * 1000), "commit point was older than " + SECONDS + " seconds (" + (lastDeleteTime - modTime) + " msec) but did not get deleted");
}
catch (System.IO.IOException)
{
// OK
break;
}
dir.DeleteFile(IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen));
gen--;
}
dir.Close();
}