本文整理汇总了C#中Lucene.Net.Index.IndexWriter.DeleteUnusedFiles方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.DeleteUnusedFiles方法的具体用法?C# IndexWriter.DeleteUnusedFiles怎么用?C# IndexWriter.DeleteUnusedFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.IndexWriter
的用法示例。
在下文中一共展示了IndexWriter.DeleteUnusedFiles方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSnapshotLastCommitTwice
public virtual void TestSnapshotLastCommitTwice()
{
Directory dir = NewDirectory();
IndexWriter writer = new IndexWriter(dir, GetConfig(Random(), DeletionPolicy));
SnapshotDeletionPolicy sdp = (SnapshotDeletionPolicy)writer.Config.DelPolicy;
writer.AddDocument(new Document());
writer.Commit();
IndexCommit s1 = sdp.Snapshot();
IndexCommit s2 = sdp.Snapshot();
Assert.AreSame(s1, s2); // should be the same instance
// create another commit
writer.AddDocument(new Document());
writer.Commit();
// release "s1" should not delete "s2"
sdp.Release(s1);
writer.DeleteUnusedFiles();
CheckSnapshotExists(dir, s2);
writer.Dispose();
dir.Dispose();
}
示例2: TestRollbackToOldSnapshot
public virtual void TestRollbackToOldSnapshot()
{
int numSnapshots = 2;
Directory dir = NewDirectory();
SnapshotDeletionPolicy sdp = DeletionPolicy;
IndexWriter writer = new IndexWriter(dir, GetConfig(Random(), sdp));
PrepareIndexAndSnapshots(sdp, writer, numSnapshots);
writer.Dispose();
// now open the writer on "snapshot0" - make sure it succeeds
writer = new IndexWriter(dir, GetConfig(Random(), sdp).SetIndexCommit(Snapshots[0]));
// this does the actual rollback
writer.Commit();
writer.DeleteUnusedFiles();
AssertSnapshotExists(dir, sdp, numSnapshots - 1, false);
writer.Dispose();
// but 'snapshot1' files will still exist (need to release snapshot before they can be deleted).
string segFileName = Snapshots[1].SegmentsFileName;
Assert.IsTrue(SlowFileExists(dir, segFileName), "snapshot files should exist in the directory: " + segFileName);
dir.Dispose();
}
示例3: TestMultiThreadedSnapshotting
public virtual void TestMultiThreadedSnapshotting()
{
Directory dir = NewDirectory();
IndexWriter writer = new IndexWriter(dir, GetConfig(Random(), DeletionPolicy));
SnapshotDeletionPolicy sdp = (SnapshotDeletionPolicy)writer.Config.DelPolicy;
ThreadClass[] threads = new ThreadClass[10];
IndexCommit[] snapshots = new IndexCommit[threads.Length];
for (int i = 0; i < threads.Length; i++)
{
int finalI = i;
threads[i] = new ThreadAnonymousInnerClassHelper2(this, writer, sdp, snapshots, finalI);
threads[i].Name = "t" + i;
}
foreach (ThreadClass t in threads)
{
t.Start();
}
foreach (ThreadClass t in threads)
{
t.Join();
}
// Do one last commit, so that after we release all snapshots, we stay w/ one commit
writer.AddDocument(new Document());
writer.Commit();
for (int i = 0; i < threads.Length; i++)
{
sdp.Release(snapshots[i]);
writer.DeleteUnusedFiles();
}
Assert.AreEqual(1, DirectoryReader.ListCommits(dir).Count);
writer.Dispose();
dir.Dispose();
}
示例4: TestReleaseSnapshot
public virtual void TestReleaseSnapshot()
{
Directory dir = NewDirectory();
IndexWriter writer = new IndexWriter(dir, GetConfig(Random(), DeletionPolicy));
SnapshotDeletionPolicy sdp = (SnapshotDeletionPolicy)writer.Config.DelPolicy;
PrepareIndexAndSnapshots(sdp, writer, 1);
// Create another commit - we must do that, because otherwise the "snapshot"
// files will still remain in the index, since it's the last commit.
writer.AddDocument(new Document());
writer.Commit();
// Release
string segFileName = Snapshots[0].SegmentsFileName;
sdp.Release(Snapshots[0]);
writer.DeleteUnusedFiles();
writer.Dispose();
Assert.IsFalse(SlowFileExists(dir, segFileName), "segments file should not be found in dirctory: " + segFileName);
dir.Dispose();
}
示例5: TestBasicSnapshots
public virtual void TestBasicSnapshots()
{
int numSnapshots = 3;
// Create 3 snapshots: snapshot0, snapshot1, snapshot2
Directory dir = NewDirectory();
IndexWriter writer = new IndexWriter(dir, GetConfig(Random(), DeletionPolicy));
SnapshotDeletionPolicy sdp = (SnapshotDeletionPolicy)writer.Config.DelPolicy;
PrepareIndexAndSnapshots(sdp, writer, numSnapshots);
writer.Dispose();
Assert.AreEqual(numSnapshots, sdp.Snapshots.Count);
Assert.AreEqual(numSnapshots, sdp.SnapshotCount);
AssertSnapshotExists(dir, sdp, numSnapshots, true);
// open a reader on a snapshot - should succeed.
DirectoryReader.Open(Snapshots[0]).Dispose();
// open a new IndexWriter w/ no snapshots to keep and assert that all snapshots are gone.
sdp = DeletionPolicy;
writer = new IndexWriter(dir, GetConfig(Random(), sdp));
writer.DeleteUnusedFiles();
writer.Dispose();
Assert.AreEqual(1, DirectoryReader.ListCommits(dir).Count, "no snapshots should exist");
dir.Dispose();
}