本文整理汇总了C#中Lucene.Net.Store.Directory.List方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Store.Directory.List方法的具体用法?C# Lucene.Net.Store.Directory.List怎么用?C# Lucene.Net.Store.Directory.List使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Store.Directory
的用法示例。
在下文中一共展示了Lucene.Net.Store.Directory.List方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentSegmentGeneration
/// <summary> Get the generation (N) of the current segments_N file
/// in the directory.
///
/// </summary>
/// <param name="directory">-- directory to search for the latest segments_N file
/// </param>
public static long GetCurrentSegmentGeneration(Directory directory)
{
System.String[] files = directory.List();
if (files == null)
{
throw new System.IO.IOException("cannot read directory " + directory + ": list() returned null");
}
return GetCurrentSegmentGeneration(files);
}
示例2: ListCommits
/** @see IndexReader#listCommits */
public static new ICollection<IndexCommitPoint> ListCommits(Directory dir)
{
string[] files = dir.List();
if (files == null)
throw new System.IO.IOException("cannot read directory " + dir + ": list() returned null");
ICollection<IndexCommitPoint> commits = new List<IndexCommitPoint>();
SegmentInfos latest = new SegmentInfos();
latest.Read(dir);
long currentGen = latest.GetGeneration();
commits.Add(new ReaderCommit(latest, dir));
for (int i = 0; i < files.Length; i++)
{
String fileName = files[i];
if (fileName.StartsWith(IndexFileNames.SEGMENTS) &&
!fileName.Equals(IndexFileNames.SEGMENTS_GEN) &&
SegmentInfos.GenerationFromSegmentsFileName(fileName) < currentGen)
{
SegmentInfos sis = new SegmentInfos();
try
{
// IOException allowed to throw there, in case
// segments_N is corrupt
sis.Read(dir, fileName);
}
catch (System.Exception)
{
// LUCENE-948: on NFS (and maybe others), if
// you have writers switching back and forth
// between machines, it's very likely that the
// dir listing will be stale and will claim a
// file segments_X exists when in fact it
// doesn't. So, we catch this and handle it
// as if the file does not exist
sis = null;
}
if (sis != null)
commits.Add(new ReaderCommit(sis, dir));
}
}
return commits;
}
示例3: AssertNoUnreferencedFiles
public static void AssertNoUnreferencedFiles(Directory dir, System.String message)
{
System.String[] startFiles = dir.List();
SegmentInfos infos = new SegmentInfos();
infos.Read(dir);
new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null);
System.String[] endFiles = dir.List();
System.Array.Sort(startFiles);
System.Array.Sort(endFiles);
//if (!startFiles.Equals(endFiles))
//{
// Assert.Fail(message + ": before delete:\n " + ArrayToString(startFiles) + "\n after delete:\n " + ArrayToString(endFiles));
//}
string startArray = ArrayToString(startFiles);
string endArray = ArrayToString(endFiles);
if (!startArray.Equals(endArray))
{
Assert.Fail(message + ": before delete:\n " + startArray + "\n after delete:\n " + endArray);
}
}
示例4: Optimize
public void Optimize(Directory directory)
{
string[] files = directory.List();
System.Collections.ArrayList segment_names = new System.Collections.ArrayList();
foreach (SegmentInfo si in this)
segment_names.Add (si.name);
foreach (string file in files) {
string basename = System.IO.Path.GetFileNameWithoutExtension (file);
if (segment_names.Contains (basename))
continue;
if (basename == IndexFileNames.DELETABLE || basename == IndexFileNames.SEGMENTS)
continue;
Console.WriteLine ("WARNING! Deleting stale data {0}", file);
directory.DeleteFile (file);
}
}
示例5: IndexFileDeleter
/// <summary> Initialize the deleter: find all previous commits in
/// the Directory, incref the files they reference, call
/// the policy to let it delete commits. The incoming
/// segmentInfos must have been loaded from a commit point
/// and not yet modified. This will remove any files not
/// referenced by any of the commits.
/// </summary>
/// <throws> CorruptIndexException if the index is corrupt </throws>
/// <throws> IOException if there is a low-level IO error </throws>
public IndexFileDeleter(Directory directory, IndexDeletionPolicy policy, SegmentInfos segmentInfos, System.IO.TextWriter infoStream, DocumentsWriter docWriter)
{
this.docWriter = docWriter;
this.infoStream = infoStream;
if (infoStream != null)
{
Message("init: current segments file is \"" + segmentInfos.GetCurrentSegmentFileName() + "\"; deletionPolicy=" + policy);
}
this.policy = policy;
this.directory = directory;
// First pass: walk the files and initialize our ref
// counts:
long currentGen = segmentInfos.GetGeneration();
IndexFileNameFilter filter = IndexFileNameFilter.GetFilter();
string[] files = directory.List();
if (files == null)
{
throw new System.IO.IOException("cannot read directory " + directory + ": list() returned null");
}
CommitPoint currentCommitPoint = null;
for (int i = 0; i < files.Length; i++)
{
string fileName = files[i];
if (filter.Accept(null, fileName) && !fileName.Equals(IndexFileNames.SEGMENTS_GEN))
{
// Add this file to refCounts with initial count 0:
GetRefCount(fileName);
if (fileName.StartsWith(IndexFileNames.SEGMENTS))
{
// This is a commit (segments or segments_N), and
// it's valid (<= the max gen). Load it, then
// incref all files it refers to:
if (SegmentInfos.GenerationFromSegmentsFileName(fileName) <= currentGen)
{
if (infoStream != null)
{
Message("init: load commit \"" + fileName + "\"");
}
SegmentInfos sis = new SegmentInfos();
try
{
sis.Read(directory, fileName);
}
catch (System.IO.FileNotFoundException)
{
// LUCENE-948: on NFS (and maybe others), if
// you have writers switching back and forth
// between machines, it's very likely that the
// dir listing will be stale and will claim a
// file segments_X exists when in fact it
// doesn't. So, we catch this and handle it
// as if the file does not exist
if (infoStream != null)
{
Message("init: hit FileNotFoundException when loading commit \"" + fileName + "\"; skipping this commit point");
}
sis = null;
}
if (sis != null)
{
CommitPoint commitPoint = new CommitPoint(this, commitsToDelete, directory, sis);
if (sis.GetGeneration() == segmentInfos.GetGeneration())
{
currentCommitPoint = commitPoint;
}
commits.Add(commitPoint);
IncRef(sis, true);
}
}
}
}
}
if (currentCommitPoint == null)
{
// We did not in fact see the segments_N file
// corresponding to the segmentInfos that was passed
// in. Yet, it must exist, because our caller holds
// the write lock. This can happen when the directory
// listing was stale (eg when index accessed via NFS
//.........这里部分代码省略.........
示例6: Optimize
public void Optimize(Directory directory)
{
string[] files = directory.List();
System.Collections.ArrayList segment_names = new System.Collections.ArrayList();
foreach (SegmentInfo si in this)
segment_names.Add (si.name);
foreach (string file in files) {
string basename = System.IO.Path.GetFileNameWithoutExtension (file);
if (segment_names.Contains (basename))
continue;
// Allowed files deletable, segments, segments.gen, segments_N
if (basename == IndexFileNames.DELETABLE || basename.StartsWith (IndexFileNames.SEGMENTS))
continue;
Console.WriteLine ("WARNING! Deleting stale data {0}", file);
try {
directory.DeleteFile (file);
} catch { /* Could be already deleted. */ }
}
}