You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by cc...@apache.org on 2013/04/03 19:39:54 UTC
[11/51] [partial] Mass convert mixed tabs to spaces
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/62f018ab/src/core/Index/IndexFileDeleter.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/IndexFileDeleter.cs b/src/core/Index/IndexFileDeleter.cs
index 3ac815d..c6afe73 100644
--- a/src/core/Index/IndexFileDeleter.cs
+++ b/src/core/Index/IndexFileDeleter.cs
@@ -59,111 +59,111 @@ namespace Lucene.Net.Index
/// instantiating this class. It opens segments_N file(s)
/// directly with no retry logic.</para>
/// </summary>
-
- public sealed class IndexFileDeleter : IDisposable
- {
-
- //// Files that we tried to delete but failed (likely
- /// because they are open and we are running on Windows),
- /// so we will retry them again later: ////
- private IList<string> deletable;
-
- //// Reference count for all files in the index.
- /// Counts how many existing commits reference a file.
- /// Maps String to RefCount (class below) instances: ////
- private IDictionary<string, RefCount> refCounts = new HashMap<string, RefCount>();
-
- //// Holds all commits (segments_N) currently in the index.
- /// This will have just 1 commit if you are using the
- /// default delete policy (KeepOnlyLastCommitDeletionPolicy).
- /// Other policies may leave commit points live for longer
- /// in which case this list would be longer than 1: ////
+
+ public sealed class IndexFileDeleter : IDisposable
+ {
+
+ //// Files that we tried to delete but failed (likely
+ /// because they are open and we are running on Windows),
+ /// so we will retry them again later: ////
+ private IList<string> deletable;
+
+ //// Reference count for all files in the index.
+ /// Counts how many existing commits reference a file.
+ /// Maps String to RefCount (class below) instances: ////
+ private IDictionary<string, RefCount> refCounts = new HashMap<string, RefCount>();
+
+ //// Holds all commits (segments_N) currently in the index.
+ /// This will have just 1 commit if you are using the
+ /// default delete policy (KeepOnlyLastCommitDeletionPolicy).
+ /// Other policies may leave commit points live for longer
+ /// in which case this list would be longer than 1: ////
private List<CommitPoint> commits = new List<CommitPoint>();
-
- //// Holds files we had incref'd from the previous
- /// non-commit checkpoint: ////
+
+ //// Holds files we had incref'd from the previous
+ /// non-commit checkpoint: ////
private List<ICollection<string>> lastFiles = new List<ICollection<string>>();
-
- //// Commits that the IndexDeletionPolicy have decided to delete: ////
+
+ //// Commits that the IndexDeletionPolicy have decided to delete: ////
private List<CommitPoint> commitsToDelete = new List<CommitPoint>();
-
- private System.IO.StreamWriter infoStream;
- private Directory directory;
- private IndexDeletionPolicy policy;
- private DocumentsWriter docWriter;
-
- internal bool startingCommitDeleted;
+
+ private System.IO.StreamWriter infoStream;
+ private Directory directory;
+ private IndexDeletionPolicy policy;
+ private DocumentsWriter docWriter;
+
+ internal bool startingCommitDeleted;
private SegmentInfos lastSegmentInfos;
private HashSet<string> synced;
-
- /// <summary>Change to true to see details of reference counts when
- /// infoStream != null
- /// </summary>
- public static bool VERBOSE_REF_COUNTS = false;
-
- internal void SetInfoStream(System.IO.StreamWriter infoStream)
- {
- this.infoStream = infoStream;
- if (infoStream != null)
- {
- Message("setInfoStream deletionPolicy=" + policy);
- }
- }
-
- private void Message(System.String message)
- {
+
+ /// <summary>Change to true to see details of reference counts when
+ /// infoStream != null
+ /// </summary>
+ public static bool VERBOSE_REF_COUNTS = false;
+
+ internal void SetInfoStream(System.IO.StreamWriter infoStream)
+ {
+ this.infoStream = infoStream;
+ if (infoStream != null)
+ {
+ Message("setInfoStream deletionPolicy=" + policy);
+ }
+ }
+
+ private void Message(System.String message)
+ {
infoStream.WriteLine("IFD [" + new DateTime().ToString() + "; " + ThreadClass.Current().Name + "]: " + message);
- }
-
- /// <summary> Initialize the deleter: find all previous commits in
- /// the Directory, incref the files they reference, call
- /// the policy to let it delete commits. 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>
+ }
+
+ /// <summary> Initialize the deleter: find all previous commits in
+ /// the Directory, incref the files they reference, call
+ /// the policy to let it delete commits. 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.StreamWriter infoStream, DocumentsWriter docWriter, HashSet<string> synced)
- {
-
- this.docWriter = docWriter;
- this.infoStream = infoStream;
+ {
+
+ this.docWriter = docWriter;
+ this.infoStream = infoStream;
this.synced = synced;
-
- 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.Generation;
- IndexFileNameFilter filter = IndexFileNameFilter.Filter;
-
- System.String[] files = directory.ListAll();
-
- CommitPoint currentCommitPoint = null;
-
- for (int i = 0; i < files.Length; i++)
- {
-
- System.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 (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.Generation;
+ IndexFileNameFilter filter = IndexFileNameFilter.Filter;
+
+ System.String[] files = directory.ListAll();
+
+ CommitPoint currentCommitPoint = null;
+
+ for (int i = 0; i < files.Length; i++)
+ {
+
+ System.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 (infoStream != null)
{
Message("init: load commit \"" + fileName + "\"");
@@ -216,68 +216,68 @@ namespace Lucene.Net.Index
{
lastSegmentInfos = sis;
}
- }
- }
- }
- }
-
- 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
- // client with stale directory listing cache). So we
- // try now to explicitly open this commit point:
- SegmentInfos sis = new SegmentInfos();
- try
- {
- sis.Read(directory, segmentInfos.GetCurrentSegmentFileName());
- }
- catch (System.IO.IOException)
- {
- throw new CorruptIndexException("failed to locate current segments_N file");
- }
- if (infoStream != null)
- Message("forced open of current segments file " + segmentInfos.GetCurrentSegmentFileName());
- currentCommitPoint = new CommitPoint(this, commitsToDelete, directory, sis);
- commits.Add(currentCommitPoint);
- IncRef(sis, true);
- }
-
- // We keep commits list in sorted order (oldest to newest):
- commits.Sort();
-
- // Now delete anything with ref count at 0. These are
- // presumably abandoned files eg due to crash of
- // IndexWriter.
- foreach(KeyValuePair<string, RefCount> entry in refCounts)
- {
+ }
+ }
+ }
+ }
+
+ 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
+ // client with stale directory listing cache). So we
+ // try now to explicitly open this commit point:
+ SegmentInfos sis = new SegmentInfos();
+ try
+ {
+ sis.Read(directory, segmentInfos.GetCurrentSegmentFileName());
+ }
+ catch (System.IO.IOException)
+ {
+ throw new CorruptIndexException("failed to locate current segments_N file");
+ }
+ if (infoStream != null)
+ Message("forced open of current segments file " + segmentInfos.GetCurrentSegmentFileName());
+ currentCommitPoint = new CommitPoint(this, commitsToDelete, directory, sis);
+ commits.Add(currentCommitPoint);
+ IncRef(sis, true);
+ }
+
+ // We keep commits list in sorted order (oldest to newest):
+ commits.Sort();
+
+ // Now delete anything with ref count at 0. These are
+ // presumably abandoned files eg due to crash of
+ // IndexWriter.
+ foreach(KeyValuePair<string, RefCount> entry in refCounts)
+ {
string fileName = entry.Key;
- RefCount rc = refCounts[fileName];
- if (0 == rc.count)
- {
- if (infoStream != null)
- {
- Message("init: removing unreferenced file \"" + fileName + "\"");
- }
- DeleteFile(fileName);
- }
- }
-
- // Finally, give policy a chance to remove things on
- // startup:
- policy.OnInit(commits);
-
- // Always protect the incoming segmentInfos since
- // sometime it may not be the most recent commit
- Checkpoint(segmentInfos, false);
-
- startingCommitDeleted = currentCommitPoint.IsDeleted;
-
- DeleteCommits();
- }
+ RefCount rc = refCounts[fileName];
+ if (0 == rc.count)
+ {
+ if (infoStream != null)
+ {
+ Message("init: removing unreferenced file \"" + fileName + "\"");
+ }
+ DeleteFile(fileName);
+ }
+ }
+
+ // Finally, give policy a chance to remove things on
+ // startup:
+ policy.OnInit(commits);
+
+ // Always protect the incoming segmentInfos since
+ // sometime it may not be the most recent commit
+ Checkpoint(segmentInfos, false);
+
+ startingCommitDeleted = currentCommitPoint.IsDeleted;
+
+ DeleteCommits();
+ }
public SegmentInfos LastSegmentInfos
{
@@ -285,264 +285,264 @@ namespace Lucene.Net.Index
}
/// <summary> Remove the CommitPoints in the commitsToDelete List by
- /// DecRef'ing all files from each SegmentInfos.
- /// </summary>
- private void DeleteCommits()
- {
-
- int size = commitsToDelete.Count;
-
- if (size > 0)
- {
-
- // First decref all files that had been referred to by
- // the now-deleted commits:
- for (int i = 0; i < size; i++)
- {
- CommitPoint commit = commitsToDelete[i];
- if (infoStream != null)
- {
- Message("deleteCommits: now decRef commit \"" + commit.SegmentsFileName + "\"");
- }
- foreach(string file in commit.files)
- {
- DecRef(file);
- }
- }
- commitsToDelete.Clear();
-
- // Now compact commits to remove deleted ones (preserving the sort):
- size = commits.Count;
- int readFrom = 0;
- int writeTo = 0;
- while (readFrom < size)
- {
- CommitPoint commit = commits[readFrom];
- if (!commit.deleted)
- {
- if (writeTo != readFrom)
- {
- commits[writeTo] = commits[readFrom];
- }
- writeTo++;
- }
- readFrom++;
- }
-
- while (size > writeTo)
- {
- commits.RemoveAt(size - 1);
- size--;
- }
- }
- }
-
- /// <summary> Writer calls this when it has hit an error and had to
- /// roll back, to tell us that there may now be
- /// unreferenced files in the filesystem. So we re-list
- /// the filesystem and delete such files. If segmentName
- /// is non-null, we will only delete files corresponding to
- /// that segment.
- /// </summary>
- public void Refresh(System.String segmentName)
- {
- System.String[] files = directory.ListAll();
- IndexFileNameFilter filter = IndexFileNameFilter.Filter;
- System.String segmentPrefix1;
- System.String segmentPrefix2;
- if (segmentName != null)
- {
- segmentPrefix1 = segmentName + ".";
- segmentPrefix2 = segmentName + "_";
- }
- else
- {
- segmentPrefix1 = null;
- segmentPrefix2 = null;
- }
-
- for (int i = 0; i < files.Length; i++)
- {
- System.String fileName = files[i];
- if (filter.Accept(null, fileName) && (segmentName == null || fileName.StartsWith(segmentPrefix1) || fileName.StartsWith(segmentPrefix2)) && !refCounts.ContainsKey(fileName) && !fileName.Equals(IndexFileNames.SEGMENTS_GEN))
- {
- // Unreferenced file, so remove it
- if (infoStream != null)
- {
- Message("refresh [prefix=" + segmentName + "]: removing newly created unreferenced file \"" + fileName + "\"");
- }
- DeleteFile(fileName);
- }
- }
- }
-
- public void Refresh()
- {
- Refresh(null);
- }
-
- public void Dispose()
- {
+ /// DecRef'ing all files from each SegmentInfos.
+ /// </summary>
+ private void DeleteCommits()
+ {
+
+ int size = commitsToDelete.Count;
+
+ if (size > 0)
+ {
+
+ // First decref all files that had been referred to by
+ // the now-deleted commits:
+ for (int i = 0; i < size; i++)
+ {
+ CommitPoint commit = commitsToDelete[i];
+ if (infoStream != null)
+ {
+ Message("deleteCommits: now decRef commit \"" + commit.SegmentsFileName + "\"");
+ }
+ foreach(string file in commit.files)
+ {
+ DecRef(file);
+ }
+ }
+ commitsToDelete.Clear();
+
+ // Now compact commits to remove deleted ones (preserving the sort):
+ size = commits.Count;
+ int readFrom = 0;
+ int writeTo = 0;
+ while (readFrom < size)
+ {
+ CommitPoint commit = commits[readFrom];
+ if (!commit.deleted)
+ {
+ if (writeTo != readFrom)
+ {
+ commits[writeTo] = commits[readFrom];
+ }
+ writeTo++;
+ }
+ readFrom++;
+ }
+
+ while (size > writeTo)
+ {
+ commits.RemoveAt(size - 1);
+ size--;
+ }
+ }
+ }
+
+ /// <summary> Writer calls this when it has hit an error and had to
+ /// roll back, to tell us that there may now be
+ /// unreferenced files in the filesystem. So we re-list
+ /// the filesystem and delete such files. If segmentName
+ /// is non-null, we will only delete files corresponding to
+ /// that segment.
+ /// </summary>
+ public void Refresh(System.String segmentName)
+ {
+ System.String[] files = directory.ListAll();
+ IndexFileNameFilter filter = IndexFileNameFilter.Filter;
+ System.String segmentPrefix1;
+ System.String segmentPrefix2;
+ if (segmentName != null)
+ {
+ segmentPrefix1 = segmentName + ".";
+ segmentPrefix2 = segmentName + "_";
+ }
+ else
+ {
+ segmentPrefix1 = null;
+ segmentPrefix2 = null;
+ }
+
+ for (int i = 0; i < files.Length; i++)
+ {
+ System.String fileName = files[i];
+ if (filter.Accept(null, fileName) && (segmentName == null || fileName.StartsWith(segmentPrefix1) || fileName.StartsWith(segmentPrefix2)) && !refCounts.ContainsKey(fileName) && !fileName.Equals(IndexFileNames.SEGMENTS_GEN))
+ {
+ // Unreferenced file, so remove it
+ if (infoStream != null)
+ {
+ Message("refresh [prefix=" + segmentName + "]: removing newly created unreferenced file \"" + fileName + "\"");
+ }
+ DeleteFile(fileName);
+ }
+ }
+ }
+
+ public void Refresh()
+ {
+ Refresh(null);
+ }
+
+ public void Dispose()
+ {
// Move to protected method if class becomes unsealed
- // DecRef old files from the last checkpoint, if any:
- int size = lastFiles.Count;
- if (size > 0)
- {
- for (int i = 0; i < size; i++)
- DecRef(lastFiles[i]);
- lastFiles.Clear();
- }
-
- DeletePendingFiles();
- }
-
- private void DeletePendingFiles()
- {
- if (deletable != null)
- {
- IList<string> oldDeletable = deletable;
- deletable = null;
- int size = oldDeletable.Count;
- for (int i = 0; i < size; i++)
- {
- if (infoStream != null)
- {
- Message("delete pending file " + oldDeletable[i]);
- }
- DeleteFile(oldDeletable[i]);
- }
- }
- }
-
- /// <summary> For definition of "check point" see IndexWriter comments:
- /// "Clarification: Check Points (and commits)".
- ///
- /// Writer calls this when it has made a "consistent
- /// change" to the index, meaning new files are written to
- /// the index and the in-memory SegmentInfos have been
- /// modified to point to those files.
- ///
- /// This may or may not be a commit (segments_N may or may
- /// not have been written).
- ///
- /// We simply incref the files referenced by the new
- /// SegmentInfos and decref the files we had previously
- /// seen (if any).
- ///
- /// If this is a commit, we also call the policy to give it
- /// a chance to remove other commits. If any commits are
- /// removed, we decref their files as well.
- /// </summary>
- public void Checkpoint(SegmentInfos segmentInfos, bool isCommit)
- {
-
- if (infoStream != null)
- {
- Message("now checkpoint \"" + segmentInfos.GetCurrentSegmentFileName() + "\" [" + segmentInfos.Count + " segments " + "; isCommit = " + isCommit + "]");
- }
-
- // Try again now to delete any previously un-deletable
- // files (because they were in use, on Windows):
- DeletePendingFiles();
-
- // Incref the files:
- IncRef(segmentInfos, isCommit);
-
- if (isCommit)
- {
- // Append to our commits list:
- commits.Add(new CommitPoint(this, commitsToDelete, directory, segmentInfos));
-
- // Tell policy so it can remove commits:
- policy.OnCommit(commits);
-
- // Decref files for commits that were deleted by the policy:
- DeleteCommits();
- }
- else
- {
-
- IList<string> docWriterFiles;
- if (docWriter != null)
- {
- docWriterFiles = docWriter.OpenFiles();
- if (docWriterFiles != null)
- // We must incRef these files before decRef'ing
- // last files to make sure we don't accidentally
- // delete them:
- IncRef(docWriterFiles);
- }
- else
- docWriterFiles = null;
-
- // DecRef old files from the last checkpoint, if any:
- int size = lastFiles.Count;
- if (size > 0)
- {
- for (int i = 0; i < size; i++)
- DecRef(lastFiles[i]);
- lastFiles.Clear();
- }
-
- // Save files so we can decr on next checkpoint/commit:
+ // DecRef old files from the last checkpoint, if any:
+ int size = lastFiles.Count;
+ if (size > 0)
+ {
+ for (int i = 0; i < size; i++)
+ DecRef(lastFiles[i]);
+ lastFiles.Clear();
+ }
+
+ DeletePendingFiles();
+ }
+
+ private void DeletePendingFiles()
+ {
+ if (deletable != null)
+ {
+ IList<string> oldDeletable = deletable;
+ deletable = null;
+ int size = oldDeletable.Count;
+ for (int i = 0; i < size; i++)
+ {
+ if (infoStream != null)
+ {
+ Message("delete pending file " + oldDeletable[i]);
+ }
+ DeleteFile(oldDeletable[i]);
+ }
+ }
+ }
+
+ /// <summary> For definition of "check point" see IndexWriter comments:
+ /// "Clarification: Check Points (and commits)".
+ ///
+ /// Writer calls this when it has made a "consistent
+ /// change" to the index, meaning new files are written to
+ /// the index and the in-memory SegmentInfos have been
+ /// modified to point to those files.
+ ///
+ /// This may or may not be a commit (segments_N may or may
+ /// not have been written).
+ ///
+ /// We simply incref the files referenced by the new
+ /// SegmentInfos and decref the files we had previously
+ /// seen (if any).
+ ///
+ /// If this is a commit, we also call the policy to give it
+ /// a chance to remove other commits. If any commits are
+ /// removed, we decref their files as well.
+ /// </summary>
+ public void Checkpoint(SegmentInfos segmentInfos, bool isCommit)
+ {
+
+ if (infoStream != null)
+ {
+ Message("now checkpoint \"" + segmentInfos.GetCurrentSegmentFileName() + "\" [" + segmentInfos.Count + " segments " + "; isCommit = " + isCommit + "]");
+ }
+
+ // Try again now to delete any previously un-deletable
+ // files (because they were in use, on Windows):
+ DeletePendingFiles();
+
+ // Incref the files:
+ IncRef(segmentInfos, isCommit);
+
+ if (isCommit)
+ {
+ // Append to our commits list:
+ commits.Add(new CommitPoint(this, commitsToDelete, directory, segmentInfos));
+
+ // Tell policy so it can remove commits:
+ policy.OnCommit(commits);
+
+ // Decref files for commits that were deleted by the policy:
+ DeleteCommits();
+ }
+ else
+ {
+
+ IList<string> docWriterFiles;
+ if (docWriter != null)
+ {
+ docWriterFiles = docWriter.OpenFiles();
+ if (docWriterFiles != null)
+ // We must incRef these files before decRef'ing
+ // last files to make sure we don't accidentally
+ // delete them:
+ IncRef(docWriterFiles);
+ }
+ else
+ docWriterFiles = null;
+
+ // DecRef old files from the last checkpoint, if any:
+ int size = lastFiles.Count;
+ if (size > 0)
+ {
+ for (int i = 0; i < size; i++)
+ DecRef(lastFiles[i]);
+ lastFiles.Clear();
+ }
+
+ // Save files so we can decr on next checkpoint/commit:
lastFiles.Add(segmentInfos.Files(directory, false));
-
+
if (docWriterFiles != null)
{
lastFiles.Add(docWriterFiles);
}
- }
- }
-
- internal void IncRef(SegmentInfos segmentInfos, bool isCommit)
- {
- // If this is a commit point, also incRef the
- // segments_N file:
- foreach(string fileName in segmentInfos.Files(directory, isCommit))
- {
- IncRef(fileName);
- }
- }
+ }
+ }
+
+ internal void IncRef(SegmentInfos segmentInfos, bool isCommit)
+ {
+ // If this is a commit point, also incRef the
+ // segments_N file:
+ foreach(string fileName in segmentInfos.Files(directory, isCommit))
+ {
+ IncRef(fileName);
+ }
+ }
internal void IncRef(ICollection<string> files)
- {
+ {
foreach(string file in files)
- {
+ {
IncRef(file);
- }
- }
-
- internal void IncRef(string fileName)
- {
- RefCount rc = GetRefCount(fileName);
- if (infoStream != null && VERBOSE_REF_COUNTS)
- {
- Message(" IncRef \"" + fileName + "\": pre-incr count is " + rc.count);
- }
- rc.IncRef();
- }
-
- internal void DecRef(ICollection<string> files)
- {
+ }
+ }
+
+ internal void IncRef(string fileName)
+ {
+ RefCount rc = GetRefCount(fileName);
+ if (infoStream != null && VERBOSE_REF_COUNTS)
+ {
+ Message(" IncRef \"" + fileName + "\": pre-incr count is " + rc.count);
+ }
+ rc.IncRef();
+ }
+
+ internal void DecRef(ICollection<string> files)
+ {
foreach(string file in files)
{
DecRef(file);
}
- }
-
- internal void DecRef(System.String fileName)
- {
- RefCount rc = GetRefCount(fileName);
- if (infoStream != null && VERBOSE_REF_COUNTS)
- {
- Message(" DecRef \"" + fileName + "\": pre-decr count is " + rc.count);
- }
- if (0 == rc.DecRef())
- {
- // This file is no longer referenced by any past
- // commit points nor by the in-memory SegmentInfos:
- DeleteFile(fileName);
- refCounts.Remove(fileName);
+ }
+
+ internal void DecRef(System.String fileName)
+ {
+ RefCount rc = GetRefCount(fileName);
+ if (infoStream != null && VERBOSE_REF_COUNTS)
+ {
+ Message(" DecRef \"" + fileName + "\": pre-decr count is " + rc.count);
+ }
+ if (0 == rc.DecRef())
+ {
+ // This file is no longer referenced by any past
+ // commit points nor by the in-memory SegmentInfos:
+ DeleteFile(fileName);
+ refCounts.Remove(fileName);
if (synced != null) {
lock(synced)
@@ -550,16 +550,16 @@ namespace Lucene.Net.Index
synced.Remove(fileName);
}
}
- }
- }
-
- internal void DecRef(SegmentInfos segmentInfos)
- {
- foreach(string file in segmentInfos.Files(directory, false))
- {
- DecRef(file);
- }
- }
+ }
+ }
+
+ internal void DecRef(SegmentInfos segmentInfos)
+ {
+ foreach(string file in segmentInfos.Files(directory, false))
+ {
+ DecRef(file);
+ }
+ }
public bool Exists(String fileName)
{
@@ -572,35 +572,35 @@ namespace Lucene.Net.Index
return GetRefCount(fileName).count > 0;
}
}
-
- private RefCount GetRefCount(System.String fileName)
- {
- RefCount rc;
- if (!refCounts.ContainsKey(fileName))
- {
- rc = new RefCount(fileName);
- refCounts[fileName] = rc;
- }
- else
- {
- rc = refCounts[fileName];
- }
- return rc;
- }
-
- internal void DeleteFiles(System.Collections.Generic.IList<string> files)
- {
- foreach(string file in files)
- DeleteFile(file);
- }
-
- /// <summary>Deletes the specified files, but only if they are new
- /// (have not yet been incref'd).
- /// </summary>
+
+ private RefCount GetRefCount(System.String fileName)
+ {
+ RefCount rc;
+ if (!refCounts.ContainsKey(fileName))
+ {
+ rc = new RefCount(fileName);
+ refCounts[fileName] = rc;
+ }
+ else
+ {
+ rc = refCounts[fileName];
+ }
+ return rc;
+ }
+
+ internal void DeleteFiles(System.Collections.Generic.IList<string> files)
+ {
+ foreach(string file in files)
+ DeleteFile(file);
+ }
+
+ /// <summary>Deletes the specified files, but only if they are new
+ /// (have not yet been incref'd).
+ /// </summary>
internal void DeleteNewFiles(System.Collections.Generic.ICollection<string> files)
- {
- foreach(string fileName in files)
- {
+ {
+ foreach(string fileName in files)
+ {
if (!refCounts.ContainsKey(fileName))
{
if (infoStream != null)
@@ -609,87 +609,87 @@ namespace Lucene.Net.Index
}
DeleteFile(fileName);
}
- }
- }
-
- internal void DeleteFile(System.String fileName)
- {
- try
- {
- if (infoStream != null)
- {
- Message("delete \"" + fileName + "\"");
- }
- directory.DeleteFile(fileName);
- }
- catch (System.IO.IOException e)
- {
- // if delete fails
- if (directory.FileExists(fileName))
- {
-
- // Some operating systems (e.g. Windows) don't
- // permit a file to be deleted while it is opened
- // for read (e.g. by another process or thread). So
- // we assume that when a delete fails it is because
- // the file is open in another process, and queue
- // the file for subsequent deletion.
-
- if (infoStream != null)
- {
- Message("IndexFileDeleter: unable to remove file \"" + fileName + "\": " + e.ToString() + "; Will re-try later.");
- }
- if (deletable == null)
- {
+ }
+ }
+
+ internal void DeleteFile(System.String fileName)
+ {
+ try
+ {
+ if (infoStream != null)
+ {
+ Message("delete \"" + fileName + "\"");
+ }
+ directory.DeleteFile(fileName);
+ }
+ catch (System.IO.IOException e)
+ {
+ // if delete fails
+ if (directory.FileExists(fileName))
+ {
+
+ // Some operating systems (e.g. Windows) don't
+ // permit a file to be deleted while it is opened
+ // for read (e.g. by another process or thread). So
+ // we assume that when a delete fails it is because
+ // the file is open in another process, and queue
+ // the file for subsequent deletion.
+
+ if (infoStream != null)
+ {
+ Message("IndexFileDeleter: unable to remove file \"" + fileName + "\": " + e.ToString() + "; Will re-try later.");
+ }
+ if (deletable == null)
+ {
deletable = new List<string>();
- }
- deletable.Add(fileName); // add to deletable
- }
- }
- }
-
- /// <summary> Tracks the reference count for a single index file:</summary>
- sealed private class RefCount
- {
-
- // fileName used only for better assert error messages
- internal System.String fileName;
- internal bool initDone;
- internal RefCount(System.String fileName)
- {
- this.fileName = fileName;
- }
-
- internal int count;
-
- public int IncRef()
- {
- if (!initDone)
- {
- initDone = true;
- }
- else
- {
- System.Diagnostics.Debug.Assert(count > 0, "RefCount is 0 pre-increment for file " + fileName);
- }
- return ++count;
- }
-
- public int DecRef()
- {
- System.Diagnostics.Debug.Assert(count > 0, "RefCount is 0 pre-decrement for file " + fileName);
- return --count;
- }
- }
-
- /// <summary> Holds details for each commit point. This class is
- /// also passed to the deletion policy. Note: this class
- /// has a natural ordering that is inconsistent with
- /// equals.
- /// </summary>
-
- sealed private class CommitPoint:IndexCommit, System.IComparable<CommitPoint>
- {
+ }
+ deletable.Add(fileName); // add to deletable
+ }
+ }
+ }
+
+ /// <summary> Tracks the reference count for a single index file:</summary>
+ sealed private class RefCount
+ {
+
+ // fileName used only for better assert error messages
+ internal System.String fileName;
+ internal bool initDone;
+ internal RefCount(System.String fileName)
+ {
+ this.fileName = fileName;
+ }
+
+ internal int count;
+
+ public int IncRef()
+ {
+ if (!initDone)
+ {
+ initDone = true;
+ }
+ else
+ {
+ System.Diagnostics.Debug.Assert(count > 0, "RefCount is 0 pre-increment for file " + fileName);
+ }
+ return ++count;
+ }
+
+ public int DecRef()
+ {
+ System.Diagnostics.Debug.Assert(count > 0, "RefCount is 0 pre-decrement for file " + fileName);
+ return --count;
+ }
+ }
+
+ /// <summary> Holds details for each commit point. This class is
+ /// also passed to the deletion policy. Note: this class
+ /// has a natural ordering that is inconsistent with
+ /// equals.
+ /// </summary>
+
+ sealed private class CommitPoint:IndexCommit, System.IComparable<CommitPoint>
+ {
private void InitBlock(IndexFileDeleter enclosingInstance)
{
this.enclosingInstance = enclosingInstance;
@@ -703,106 +703,106 @@ namespace Lucene.Net.Index
}
}
-
- internal long gen;
+
+ internal long gen;
internal ICollection<string> files;
- internal string segmentsFileName;
- internal bool deleted;
- internal Directory directory;
+ internal string segmentsFileName;
+ internal bool deleted;
+ internal Directory directory;
internal ICollection<CommitPoint> commitsToDelete;
- internal long version;
- internal long generation;
- internal bool isOptimized;
+ internal long version;
+ internal long generation;
+ internal bool isOptimized;
internal IDictionary<string, string> userData;
-
- public CommitPoint(IndexFileDeleter enclosingInstance, ICollection<CommitPoint> commitsToDelete, Directory directory, SegmentInfos segmentInfos)
- {
- InitBlock(enclosingInstance);
- this.directory = directory;
- this.commitsToDelete = commitsToDelete;
- userData = segmentInfos.UserData;
- segmentsFileName = segmentInfos.GetCurrentSegmentFileName();
- version = segmentInfos.Version;
- generation = segmentInfos.Generation;
+
+ public CommitPoint(IndexFileDeleter enclosingInstance, ICollection<CommitPoint> commitsToDelete, Directory directory, SegmentInfos segmentInfos)
+ {
+ InitBlock(enclosingInstance);
+ this.directory = directory;
+ this.commitsToDelete = commitsToDelete;
+ userData = segmentInfos.UserData;
+ segmentsFileName = segmentInfos.GetCurrentSegmentFileName();
+ version = segmentInfos.Version;
+ generation = segmentInfos.Generation;
files = segmentInfos.Files(directory, true);
- gen = segmentInfos.Generation;
- isOptimized = segmentInfos.Count == 1 && !segmentInfos.Info(0).HasDeletions();
-
- System.Diagnostics.Debug.Assert(!segmentInfos.HasExternalSegments(directory));
- }
+ gen = segmentInfos.Generation;
+ isOptimized = segmentInfos.Count == 1 && !segmentInfos.Info(0).HasDeletions();
+
+ System.Diagnostics.Debug.Assert(!segmentInfos.HasExternalSegments(directory));
+ }
public override string ToString()
{
return "IndexFileDeleter.CommitPoint(" + segmentsFileName + ")";
}
- public override bool IsOptimized
- {
- get { return isOptimized; }
- }
+ public override bool IsOptimized
+ {
+ get { return isOptimized; }
+ }
- public override string SegmentsFileName
- {
- get { return segmentsFileName; }
- }
+ public override string SegmentsFileName
+ {
+ get { return segmentsFileName; }
+ }
- public override ICollection<string> FileNames
- {
- get { return files; }
- }
+ public override ICollection<string> FileNames
+ {
+ get { return files; }
+ }
- public override Directory Directory
- {
- get { return directory; }
- }
+ public override Directory Directory
+ {
+ get { return directory; }
+ }
- public override long Version
- {
- get { return version; }
- }
+ public override long Version
+ {
+ get { return version; }
+ }
- public override long Generation
- {
- get { return generation; }
- }
+ public override long Generation
+ {
+ get { return generation; }
+ }
- public override IDictionary<string, string> UserData
- {
- get { return userData; }
- }
+ public override IDictionary<string, string> UserData
+ {
+ get { return userData; }
+ }
- /// <summary> Called only be the deletion policy, to remove this
- /// commit point from the index.
- /// </summary>
- public override void Delete()
- {
- if (!deleted)
- {
- deleted = true;
- Enclosing_Instance.commitsToDelete.Add(this);
- }
- }
+ /// <summary> Called only be the deletion policy, to remove this
+ /// commit point from the index.
+ /// </summary>
+ public override void Delete()
+ {
+ if (!deleted)
+ {
+ deleted = true;
+ Enclosing_Instance.commitsToDelete.Add(this);
+ }
+ }
- public override bool IsDeleted
- {
- get { return deleted; }
- }
+ public override bool IsDeleted
+ {
+ get { return deleted; }
+ }
- public int CompareTo(CommitPoint commit)
- {
- if (gen < commit.gen)
- {
- return - 1;
- }
- else if (gen > commit.gen)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- }
- }
+ public int CompareTo(CommitPoint commit)
+ {
+ if (gen < commit.gen)
+ {
+ return - 1;
+ }
+ else if (gen > commit.gen)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/62f018ab/src/core/Index/IndexFileNameFilter.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/IndexFileNameFilter.cs b/src/core/Index/IndexFileNameFilter.cs
index 474381f..f8abe25 100644
--- a/src/core/Index/IndexFileNameFilter.cs
+++ b/src/core/Index/IndexFileNameFilter.cs
@@ -20,88 +20,88 @@ using System.Collections.Generic;
namespace Lucene.Net.Index
{
-
- /// <summary>Filename filter that accept filenames and extensions only created by Lucene. </summary>
- public class IndexFileNameFilter
- {
-
- private static IndexFileNameFilter singleton = new IndexFileNameFilter();
+
+ /// <summary>Filename filter that accept filenames and extensions only created by Lucene. </summary>
+ public class IndexFileNameFilter
+ {
+
+ private static IndexFileNameFilter singleton = new IndexFileNameFilter();
private HashSet<String> extensions;
private HashSet<String> extensionsInCFS;
-
- // Prevent instantiation.
- private IndexFileNameFilter()
- {
+
+ // Prevent instantiation.
+ private IndexFileNameFilter()
+ {
extensions = new HashSet<String>();
- for (int i = 0; i < IndexFileNames.INDEX_EXTENSIONS.Length; i++)
- {
- extensions.Add(IndexFileNames.INDEX_EXTENSIONS[i]);
- }
+ for (int i = 0; i < IndexFileNames.INDEX_EXTENSIONS.Length; i++)
+ {
+ extensions.Add(IndexFileNames.INDEX_EXTENSIONS[i]);
+ }
extensionsInCFS = new HashSet<String>();
- for (int i = 0; i < IndexFileNames.INDEX_EXTENSIONS_IN_COMPOUND_FILE.Length; i++)
- {
- extensionsInCFS.Add(IndexFileNames.INDEX_EXTENSIONS_IN_COMPOUND_FILE[i]);
- }
- }
-
- /* (non-Javadoc)
- * <see cref="java.io.FilenameFilter.accept(java.io.File, java.lang.String)"/>
- */
- public virtual bool Accept(System.IO.FileInfo dir, System.String name)
- {
- int i = name.LastIndexOf((System.Char) '.');
- if (i != - 1)
- {
- System.String extension = name.Substring(1 + i);
- if (extensions.Contains(extension))
- {
- return true;
- }
- else if (extension.StartsWith("f") && (new System.Text.RegularExpressions.Regex("f\\d+")).Match(extension).Success)
- {
- return true;
- }
- else if (extension.StartsWith("s") && (new System.Text.RegularExpressions.Regex("s\\d+")).Match(extension).Success)
- {
- return true;
- }
- }
- else
- {
- if (name.Equals(IndexFileNames.DELETABLE))
- return true;
- else if (name.StartsWith(IndexFileNames.SEGMENTS))
- return true;
- }
- return false;
- }
-
- /// <summary> Returns true if this is a file that would be contained
- /// in a CFS file. This function should only be called on
- /// files that pass the above "accept" (ie, are already
- /// known to be a Lucene index file).
- /// </summary>
- public virtual bool IsCFSFile(System.String name)
- {
- int i = name.LastIndexOf((System.Char) '.');
- if (i != - 1)
- {
- System.String extension = name.Substring(1 + i);
- if (extensionsInCFS.Contains(extension))
- {
- return true;
- }
- if (extension.StartsWith("f") && (new System.Text.RegularExpressions.Regex("f\\d+")).Match(extension).Success)
- {
- return true;
- }
- }
- return false;
- }
+ for (int i = 0; i < IndexFileNames.INDEX_EXTENSIONS_IN_COMPOUND_FILE.Length; i++)
+ {
+ extensionsInCFS.Add(IndexFileNames.INDEX_EXTENSIONS_IN_COMPOUND_FILE[i]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * <see cref="java.io.FilenameFilter.accept(java.io.File, java.lang.String)"/>
+ */
+ public virtual bool Accept(System.IO.FileInfo dir, System.String name)
+ {
+ int i = name.LastIndexOf((System.Char) '.');
+ if (i != - 1)
+ {
+ System.String extension = name.Substring(1 + i);
+ if (extensions.Contains(extension))
+ {
+ return true;
+ }
+ else if (extension.StartsWith("f") && (new System.Text.RegularExpressions.Regex("f\\d+")).Match(extension).Success)
+ {
+ return true;
+ }
+ else if (extension.StartsWith("s") && (new System.Text.RegularExpressions.Regex("s\\d+")).Match(extension).Success)
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (name.Equals(IndexFileNames.DELETABLE))
+ return true;
+ else if (name.StartsWith(IndexFileNames.SEGMENTS))
+ return true;
+ }
+ return false;
+ }
+
+ /// <summary> Returns true if this is a file that would be contained
+ /// in a CFS file. This function should only be called on
+ /// files that pass the above "accept" (ie, are already
+ /// known to be a Lucene index file).
+ /// </summary>
+ public virtual bool IsCFSFile(System.String name)
+ {
+ int i = name.LastIndexOf((System.Char) '.');
+ if (i != - 1)
+ {
+ System.String extension = name.Substring(1 + i);
+ if (extensionsInCFS.Contains(extension))
+ {
+ return true;
+ }
+ if (extension.StartsWith("f") && (new System.Text.RegularExpressions.Regex("f\\d+")).Match(extension).Success)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
- public static IndexFileNameFilter Filter
- {
- get { return singleton; }
- }
- }
+ public static IndexFileNameFilter Filter
+ {
+ get { return singleton; }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/62f018ab/src/core/Index/IndexFileNames.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/IndexFileNames.cs b/src/core/Index/IndexFileNames.cs
index ef50119..130d7af 100644
--- a/src/core/Index/IndexFileNames.cs
+++ b/src/core/Index/IndexFileNames.cs
@@ -20,146 +20,146 @@ using Lucene.Net.Support;
namespace Lucene.Net.Index
{
-
- /// <summary>Useful constants representing filenames and extensions used by lucene</summary>
- public sealed class IndexFileNames
- {
-
- /// <summary>Name of the index segment file </summary>
- public /*internal*/ const System.String SEGMENTS = "segments";
-
- /// <summary>Name of the generation reference file name </summary>
- public /*internal*/ const System.String SEGMENTS_GEN = "segments.gen";
-
- /// <summary>Name of the index deletable file (only used in
- /// pre-lockless indices)
- /// </summary>
- public /*internal*/ const System.String DELETABLE = "deletable";
-
- /// <summary>Extension of norms file </summary>
- public /*internal*/ const System.String NORMS_EXTENSION = "nrm";
-
- /// <summary>Extension of freq postings file </summary>
- public /*internal*/ const System.String FREQ_EXTENSION = "frq";
-
- /// <summary>Extension of prox postings file </summary>
- public /*internal*/ const System.String PROX_EXTENSION = "prx";
-
- /// <summary>Extension of terms file </summary>
- public /*internal*/ const System.String TERMS_EXTENSION = "tis";
-
- /// <summary>Extension of terms index file </summary>
- public /*internal*/ const System.String TERMS_INDEX_EXTENSION = "tii";
-
- /// <summary>Extension of stored fields index file </summary>
- public /*internal*/ const System.String FIELDS_INDEX_EXTENSION = "fdx";
-
- /// <summary>Extension of stored fields file </summary>
- public /*internal*/ const System.String FIELDS_EXTENSION = "fdt";
-
- /// <summary>Extension of vectors fields file </summary>
- public /*internal*/ const System.String VECTORS_FIELDS_EXTENSION = "tvf";
-
- /// <summary>Extension of vectors documents file </summary>
- public /*internal*/ const System.String VECTORS_DOCUMENTS_EXTENSION = "tvd";
-
- /// <summary>Extension of vectors index file </summary>
- public /*internal*/ const System.String VECTORS_INDEX_EXTENSION = "tvx";
-
- /// <summary>Extension of compound file </summary>
- public /*internal*/ const System.String COMPOUND_FILE_EXTENSION = "cfs";
-
- /// <summary>Extension of compound file for doc store files</summary>
- public /*internal*/ const System.String COMPOUND_FILE_STORE_EXTENSION = "cfx";
-
- /// <summary>Extension of deletes </summary>
- internal const System.String DELETES_EXTENSION = "del";
-
- /// <summary>Extension of field infos </summary>
- public /*internal*/ const System.String FIELD_INFOS_EXTENSION = "fnm";
-
- /// <summary>Extension of plain norms </summary>
- public /*internal*/ const System.String PLAIN_NORMS_EXTENSION = "f";
-
- /// <summary>Extension of separate norms </summary>
- public /*internal*/ const System.String SEPARATE_NORMS_EXTENSION = "s";
-
- /// <summary>Extension of gen file </summary>
- public /*internal*/ const System.String GEN_EXTENSION = "gen";
-
- /// <summary> This array contains all filename extensions used by
- /// Lucene's index files, with two exceptions, namely the
- /// extension made up from <c>.f</c> + a number and
- /// from <c>.s</c> + a number. Also note that
- /// Lucene's <c>segments_N</c> files do not have any
- /// filename extension.
- /// </summary>
- public /*internal*/ static readonly System.String[] INDEX_EXTENSIONS = new System.String[]{COMPOUND_FILE_EXTENSION, FIELD_INFOS_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION, TERMS_INDEX_EXTENSION, TERMS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, DELETES_EXTENSION, VECTORS_INDEX_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION, GEN_EXTENSION, NORMS_EXTENSION, COMPOUND_FILE_STORE_EXTENSION};
-
- /// <summary>File extensions that are added to a compound file
- /// (same as above, minus "del", "gen", "cfs").
- /// </summary>
- public /*internal*/ static readonly System.String[] INDEX_EXTENSIONS_IN_COMPOUND_FILE = new System.String[]{FIELD_INFOS_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION, TERMS_INDEX_EXTENSION, TERMS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, VECTORS_INDEX_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION, NORMS_EXTENSION};
-
- public /*internal*/ static readonly System.String[] STORE_INDEX_EXTENSIONS = new System.String[]{VECTORS_INDEX_EXTENSION, VECTORS_FIELDS_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION};
-
- public /*internal*/ static readonly System.String[] NON_STORE_INDEX_EXTENSIONS = new System.String[]{FIELD_INFOS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, TERMS_EXTENSION, TERMS_INDEX_EXTENSION, NORMS_EXTENSION};
-
- /// <summary>File extensions of old-style index files </summary>
- public /*internal*/ static readonly System.String[] COMPOUND_EXTENSIONS = new System.String[]{FIELD_INFOS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION, TERMS_INDEX_EXTENSION, TERMS_EXTENSION};
-
- /// <summary>File extensions for term vector support </summary>
- public /*internal*/ static readonly System.String[] VECTOR_EXTENSIONS = new System.String[]{VECTORS_INDEX_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION};
-
- /// <summary> Computes the full file name from base, extension and
- /// generation. If the generation is -1, the file name is
- /// null. If it's 0, the file name is
- /// If it's > 0, the file name is
- ///
- /// </summary>
+
+ /// <summary>Useful constants representing filenames and extensions used by lucene</summary>
+ public sealed class IndexFileNames
+ {
+
+ /// <summary>Name of the index segment file </summary>
+ public /*internal*/ const System.String SEGMENTS = "segments";
+
+ /// <summary>Name of the generation reference file name </summary>
+ public /*internal*/ const System.String SEGMENTS_GEN = "segments.gen";
+
+ /// <summary>Name of the index deletable file (only used in
+ /// pre-lockless indices)
+ /// </summary>
+ public /*internal*/ const System.String DELETABLE = "deletable";
+
+ /// <summary>Extension of norms file </summary>
+ public /*internal*/ const System.String NORMS_EXTENSION = "nrm";
+
+ /// <summary>Extension of freq postings file </summary>
+ public /*internal*/ const System.String FREQ_EXTENSION = "frq";
+
+ /// <summary>Extension of prox postings file </summary>
+ public /*internal*/ const System.String PROX_EXTENSION = "prx";
+
+ /// <summary>Extension of terms file </summary>
+ public /*internal*/ const System.String TERMS_EXTENSION = "tis";
+
+ /// <summary>Extension of terms index file </summary>
+ public /*internal*/ const System.String TERMS_INDEX_EXTENSION = "tii";
+
+ /// <summary>Extension of stored fields index file </summary>
+ public /*internal*/ const System.String FIELDS_INDEX_EXTENSION = "fdx";
+
+ /// <summary>Extension of stored fields file </summary>
+ public /*internal*/ const System.String FIELDS_EXTENSION = "fdt";
+
+ /// <summary>Extension of vectors fields file </summary>
+ public /*internal*/ const System.String VECTORS_FIELDS_EXTENSION = "tvf";
+
+ /// <summary>Extension of vectors documents file </summary>
+ public /*internal*/ const System.String VECTORS_DOCUMENTS_EXTENSION = "tvd";
+
+ /// <summary>Extension of vectors index file </summary>
+ public /*internal*/ const System.String VECTORS_INDEX_EXTENSION = "tvx";
+
+ /// <summary>Extension of compound file </summary>
+ public /*internal*/ const System.String COMPOUND_FILE_EXTENSION = "cfs";
+
+ /// <summary>Extension of compound file for doc store files</summary>
+ public /*internal*/ const System.String COMPOUND_FILE_STORE_EXTENSION = "cfx";
+
+ /// <summary>Extension of deletes </summary>
+ internal const System.String DELETES_EXTENSION = "del";
+
+ /// <summary>Extension of field infos </summary>
+ public /*internal*/ const System.String FIELD_INFOS_EXTENSION = "fnm";
+
+ /// <summary>Extension of plain norms </summary>
+ public /*internal*/ const System.String PLAIN_NORMS_EXTENSION = "f";
+
+ /// <summary>Extension of separate norms </summary>
+ public /*internal*/ const System.String SEPARATE_NORMS_EXTENSION = "s";
+
+ /// <summary>Extension of gen file </summary>
+ public /*internal*/ const System.String GEN_EXTENSION = "gen";
+
+ /// <summary> This array contains all filename extensions used by
+ /// Lucene's index files, with two exceptions, namely the
+ /// extension made up from <c>.f</c> + a number and
+ /// from <c>.s</c> + a number. Also note that
+ /// Lucene's <c>segments_N</c> files do not have any
+ /// filename extension.
+ /// </summary>
+ public /*internal*/ static readonly System.String[] INDEX_EXTENSIONS = new System.String[]{COMPOUND_FILE_EXTENSION, FIELD_INFOS_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION, TERMS_INDEX_EXTENSION, TERMS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, DELETES_EXTENSION, VECTORS_INDEX_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION, GEN_EXTENSION, NORMS_EXTENSION, COMPOUND_FILE_STORE_EXTENSION};
+
+ /// <summary>File extensions that are added to a compound file
+ /// (same as above, minus "del", "gen", "cfs").
+ /// </summary>
+ public /*internal*/ static readonly System.String[] INDEX_EXTENSIONS_IN_COMPOUND_FILE = new System.String[]{FIELD_INFOS_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION, TERMS_INDEX_EXTENSION, TERMS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, VECTORS_INDEX_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION, NORMS_EXTENSION};
+
+ public /*internal*/ static readonly System.String[] STORE_INDEX_EXTENSIONS = new System.String[]{VECTORS_INDEX_EXTENSION, VECTORS_FIELDS_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION};
+
+ public /*internal*/ static readonly System.String[] NON_STORE_INDEX_EXTENSIONS = new System.String[]{FIELD_INFOS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, TERMS_EXTENSION, TERMS_INDEX_EXTENSION, NORMS_EXTENSION};
+
+ /// <summary>File extensions of old-style index files </summary>
+ public /*internal*/ static readonly System.String[] COMPOUND_EXTENSIONS = new System.String[]{FIELD_INFOS_EXTENSION, FREQ_EXTENSION, PROX_EXTENSION, FIELDS_INDEX_EXTENSION, FIELDS_EXTENSION, TERMS_INDEX_EXTENSION, TERMS_EXTENSION};
+
+ /// <summary>File extensions for term vector support </summary>
+ public /*internal*/ static readonly System.String[] VECTOR_EXTENSIONS = new System.String[]{VECTORS_INDEX_EXTENSION, VECTORS_DOCUMENTS_EXTENSION, VECTORS_FIELDS_EXTENSION};
+
+ /// <summary> Computes the full file name from base, extension and
+ /// generation. If the generation is -1, the file name is
+ /// null. If it's 0, the file name is
+ /// If it's > 0, the file name is
+ ///
+ /// </summary>
/// <param name="base_Renamed">-- main part of the file name
- /// </param>
- /// <param name="extension">-- extension of the filename (including .)
- /// </param>
- /// <param name="gen">-- generation
- /// </param>
- public /*internal*/ static System.String FileNameFromGeneration(System.String base_Renamed, System.String extension, long gen)
- {
- if (gen == SegmentInfo.NO)
- {
- return null;
- }
- else if (gen == SegmentInfo.WITHOUT_GEN)
- {
- return base_Renamed + extension;
- }
- else
- {
+ /// </param>
+ /// <param name="extension">-- extension of the filename (including .)
+ /// </param>
+ /// <param name="gen">-- generation
+ /// </param>
+ public /*internal*/ static System.String FileNameFromGeneration(System.String base_Renamed, System.String extension, long gen)
+ {
+ if (gen == SegmentInfo.NO)
+ {
+ return null;
+ }
+ else if (gen == SegmentInfo.WITHOUT_GEN)
+ {
+ return base_Renamed + extension;
+ }
+ else
+ {
#if !PRE_LUCENE_NET_2_0_0_COMPATIBLE
- return base_Renamed + "_" + Number.ToString(gen) + extension;
+ return base_Renamed + "_" + Number.ToString(gen) + extension;
#else
- return base_Renamed + "_" + System.Convert.ToString(gen, 16) + extension;
+ return base_Renamed + "_" + System.Convert.ToString(gen, 16) + extension;
#endif
- }
- }
-
- /// <summary> Returns true if the provided filename is one of the doc
- /// store files (ends with an extension in
- /// STORE_INDEX_EXTENSIONS).
- /// </summary>
- internal static bool IsDocStoreFile(System.String fileName)
- {
- if (fileName.EndsWith(COMPOUND_FILE_STORE_EXTENSION))
- return true;
- for (int i = 0; i < STORE_INDEX_EXTENSIONS.Length; i++)
- if (fileName.EndsWith(STORE_INDEX_EXTENSIONS[i]))
- return true;
- return false;
- }
-
- internal static System.String SegmentFileName(System.String segmentName, System.String ext)
- {
- return segmentName + "." + ext;
- }
- }
+ }
+ }
+
+ /// <summary> Returns true if the provided filename is one of the doc
+ /// store files (ends with an extension in
+ /// STORE_INDEX_EXTENSIONS).
+ /// </summary>
+ internal static bool IsDocStoreFile(System.String fileName)
+ {
+ if (fileName.EndsWith(COMPOUND_FILE_STORE_EXTENSION))
+ return true;
+ for (int i = 0; i < STORE_INDEX_EXTENSIONS.Length; i++)
+ if (fileName.EndsWith(STORE_INDEX_EXTENSIONS[i]))
+ return true;
+ return false;
+ }
+
+ internal static System.String SegmentFileName(System.String segmentName, System.String ext)
+ {
+ return segmentName + "." + ext;
+ }
+ }
}
\ No newline at end of file