本文整理汇总了C#中Lucene.Net.Index.SegmentInfos.Files方法的典型用法代码示例。如果您正苦于以下问题:C# SegmentInfos.Files方法的具体用法?C# SegmentInfos.Files怎么用?C# SegmentInfos.Files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Index.SegmentInfos
的用法示例。
在下文中一共展示了SegmentInfos.Files方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DirectoryReader
/// <summary>Construct reading the named set of readers. </summary>
internal DirectoryReader(Directory directory, SegmentInfos sis, IndexDeletionPolicy deletionPolicy, bool readOnly, int termInfosIndexDivisor)
{
this.directory = directory;
this.readOnly = readOnly;
this.segmentInfos = sis;
this.deletionPolicy = deletionPolicy;
this.termInfosIndexDivisor = termInfosIndexDivisor;
if (!readOnly)
{
// We assume that this segments_N was previously
// properly sync'd:
SupportClass.CollectionsHelper.AddAllIfNotContains(synced, sis.Files(directory, true));
}
// To reduce the chance of hitting FileNotFound
// (and having to retry), we open segments in
// reverse because IndexWriter merges & deletes
// the newest segments first.
SegmentReader[] readers = new SegmentReader[sis.Count];
for (int i = sis.Count - 1; i >= 0; i--)
{
bool success = false;
try
{
readers[i] = SegmentReader.Get(readOnly, sis.Info(i), termInfosIndexDivisor);
success = true;
}
finally
{
if (!success)
{
// Close all readers we had opened:
for (i++; i < sis.Count; i++)
{
try
{
readers[i].Close();
}
catch (System.Exception ignore)
{
// keep going - we want to clean up as much as possible
}
}
}
}
}
Initialize(readers);
}
示例2: Checkpoint
/// <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
{
System.Collections.Generic.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:
foreach (string fname in segmentInfos.Files(directory, false))
{
lastFiles.Add(fname);
}
if (docWriterFiles != null)
{
foreach (string fname in docWriterFiles)
{
lastFiles.Add(fname);
}
}
}
}
示例3: StartCommit
/// <summary>
/// Walk through all files referenced by the current
/// segmentInfos and ask the Directory to sync each file,
/// if it wasn't already. If that succeeds, then we
/// prepare a new segments_N file but do not fully commit
/// it.
/// </summary>
private void StartCommit(SegmentInfos toSync)
{
Debug.Assert(TestPoint("startStartCommit"));
Debug.Assert(PendingCommit == null);
if (HitOOM)
{
throw new InvalidOperationException("this writer hit an OutOfMemoryError; cannot commit");
}
try
{
if (infoStream.IsEnabled("IW"))
{
infoStream.Message("IW", "startCommit(): start");
}
lock (this)
{
Debug.Assert(LastCommitChangeCount <= ChangeCount, "lastCommitChangeCount=" + LastCommitChangeCount + " changeCount=" + ChangeCount);
if (PendingCommitChangeCount == LastCommitChangeCount)
{
if (infoStream.IsEnabled("IW"))
{
infoStream.Message("IW", " skip startCommit(): no changes pending");
}
Deleter.DecRef(FilesToCommit);
FilesToCommit = null;
return;
}
if (infoStream.IsEnabled("IW"))
{
infoStream.Message("IW", "startCommit index=" + SegString(ToLiveInfos(toSync).Segments) + " changeCount=" + ChangeCount);
}
Debug.Assert(FilesExist(toSync));
}
Debug.Assert(TestPoint("midStartCommit"));
bool pendingCommitSet = false;
try
{
Debug.Assert(TestPoint("midStartCommit2"));
lock (this)
{
Debug.Assert(PendingCommit == null);
Debug.Assert(segmentInfos.Generation == toSync.Generation);
// Exception here means nothing is prepared
// (this method unwinds everything it did on
// an exception)
toSync.PrepareCommit(directory);
//System.out.println("DONE prepareCommit");
pendingCommitSet = true;
PendingCommit = toSync;
}
// this call can take a long time -- 10s of seconds
// or more. We do it without syncing on this:
bool success = false;
ICollection<string> filesToSync;
try
{
filesToSync = toSync.Files(directory, false);
directory.Sync(filesToSync);
success = true;
}
finally
{
if (!success)
{
pendingCommitSet = false;
PendingCommit = null;
toSync.RollbackCommit(directory);
}
}
if (infoStream.IsEnabled("IW"))
{
infoStream.Message("IW", "done all syncs: " + filesToSync);
}
Debug.Assert(TestPoint("midStartCommitSuccess"));
}
finally
{
//.........这里部分代码省略.........
示例4: FilesExist
// called only from assert
private bool FilesExist(SegmentInfos toSync)
{
ICollection<string> files = toSync.Files(directory, false);
foreach (String fileName in files)
{
Debug.Assert(SlowFileExists(directory, fileName), "file " + fileName + " does not exist; files=" + Arrays.ToString(directory.ListAll()));
// If this trips it means we are missing a call to
// .checkpoint somewhere, because by the time we
// are called, deleter should know about every
// file referenced by the current head
// segmentInfos:
Debug.Assert(Deleter.Exists(fileName), "IndexFileDeleter doesn't know about file " + fileName);
}
return true;
}
示例5: DirectoryReader
/// <summary>This constructor is only used for <see cref="Reopen()" /> </summary>
internal DirectoryReader(Directory directory, SegmentInfos infos, SegmentReader[] oldReaders, int[] oldStarts,
IEnumerable<KeyValuePair<string, byte[]>> oldNormsCache, bool readOnly, bool doClone, int termInfosIndexDivisor)
{
this.internalDirectory = directory;
this.readOnly = readOnly;
this.segmentInfos = infos;
this.termInfosIndexDivisor = termInfosIndexDivisor;
if (!readOnly)
{
// We assume that this segments_N was previously
// properly sync'd:
synced.UnionWith(infos.Files(directory, true));
}
// we put the old SegmentReaders in a map, that allows us
// to lookup a reader using its segment name
IDictionary<string, int> segmentReaders = new HashMap<string, int>();
if (oldReaders != null)
{
// create a Map SegmentName->SegmentReader
for (int i = 0; i < oldReaders.Length; i++)
{
segmentReaders[oldReaders[i].SegmentName] = i;
}
}
var newReaders = new SegmentReader[infos.Count];
// remember which readers are shared between the old and the re-opened
// DirectoryReader - we have to incRef those readers
var readerShared = new bool[infos.Count];
for (int i = infos.Count - 1; i >= 0; i--)
{
// find SegmentReader for this segment
if (!segmentReaders.ContainsKey(infos.Info(i).name))
{
// this is a new segment, no old SegmentReader can be reused
newReaders[i] = null;
}
else
{
// there is an old reader for this segment - we'll try to reopen it
newReaders[i] = oldReaders[segmentReaders[infos.Info(i).name]];
}
bool success = false;
try
{
SegmentReader newReader;
if (newReaders[i] == null || infos.Info(i).GetUseCompoundFile() != newReaders[i].SegmentInfo.GetUseCompoundFile())
{
// We should never see a totally new segment during cloning
System.Diagnostics.Debug.Assert(!doClone);
// this is a new reader; in case we hit an exception we can close it safely
newReader = SegmentReader.Get(readOnly, infos.Info(i), termInfosIndexDivisor);
}
else
{
newReader = newReaders[i].ReopenSegment(infos.Info(i), doClone, readOnly);
}
if (newReader == newReaders[i])
{
// this reader will be shared between the old and the new one,
// so we must incRef it
readerShared[i] = true;
newReader.IncRef();
}
else
{
readerShared[i] = false;
newReaders[i] = newReader;
}
success = true;
}
finally
{
if (!success)
{
for (i++; i < infos.Count; i++)
{
if (newReaders[i] != null)
{
try
{
if (!readerShared[i])
{
// this is a new subReader that is not used by the old one,
// we can close it
newReaders[i].Close();
}
else
{
// this subReader is also used by the old reader, so instead
// closing we must decRef it
newReaders[i].DecRef();
//.........这里部分代码省略.........
示例6: IncRef
internal void IncRef(SegmentInfos segmentInfos, bool isCommit)
{
// If this is a commit point, also incRef the
// segments_N file:
System.Collections.IEnumerator it = segmentInfos.Files(directory, isCommit).GetEnumerator();
while (it.MoveNext())
{
IncRef((System.String) ((System.Collections.DictionaryEntry) it.Current).Key);
}
}
示例7: CommitPoint
public CommitPoint(IndexFileDeleter enclosingInstance, System.Collections.ICollection commitsToDelete, Directory directory, SegmentInfos segmentInfos)
{
InitBlock(enclosingInstance);
this.directory = directory;
this.commitsToDelete = commitsToDelete;
userData = segmentInfos.GetUserData();
segmentsFileName = segmentInfos.GetCurrentSegmentFileName();
version = segmentInfos.GetVersion();
generation = segmentInfos.GetGeneration();
files = segmentInfos.Files(directory, true);
gen = segmentInfos.GetGeneration();
isOptimized = segmentInfos.Count == 1 && !segmentInfos.Info(0).HasDeletions();
System.Diagnostics.Debug.Assert(!segmentInfos.HasExternalSegments(directory));
}
示例8: CommitPoint
public CommitPoint(ICollection<CommitPoint> commitsToDelete, Directory directory, SegmentInfos segmentInfos)
{
this.Directory_Renamed = directory;
this.CommitsToDelete = commitsToDelete;
UserData_Renamed = segmentInfos.UserData;
SegmentsFileName_Renamed = segmentInfos.SegmentsFileName;
Generation_Renamed = segmentInfos.Generation;
Files = segmentInfos.Files(directory, true);
SegmentCount_Renamed = segmentInfos.Size();
}
示例9: DecRef
internal void DecRef(SegmentInfos segmentInfos)
{
Debug.Assert(Locked());
foreach (String file in segmentInfos.Files(Directory, false))
{
DecRef(file);
}
}
示例10: IncRef
internal void IncRef(SegmentInfos segmentInfos, bool isCommit)
{
Debug.Assert(Locked());
// If this is a commit point, also incRef the
// segments_N file:
foreach (String fileName in segmentInfos.Files(Directory, isCommit))
{
IncRef(fileName);
}
}
示例11: Checkpoint
/// <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)
{
Debug.Assert(Locked());
//Debug.Assert(Thread.holdsLock(Writer));
long t0 = 0;
if (InfoStream.IsEnabled("IFD"))
{
t0 = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;
InfoStream.Message("IFD", "now checkpoint \"" + Writer.SegString(Writer.ToLiveInfos(segmentInfos).Segments) + "\" [" + segmentInfos.Size() + " 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(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
{
// DecRef old files from the last checkpoint, if any:
DecRef(LastFiles);
LastFiles.Clear();
// Save files so we can decr on next checkpoint/commit:
LastFiles.AddRange(segmentInfos.Files(Directory, false));
}
if (InfoStream.IsEnabled("IFD"))
{
long t1 = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;
InfoStream.Message("IFD", ((t1 - t0) / 1000000) + " msec to checkpoint");
}
}
示例12: ReaderCommit
internal ReaderCommit(SegmentInfos infos, Directory dir)
{
segmentsFileName = infos.GetCurrentSegmentFileName();
this.dir = dir;
userData = infos.GetUserData();
files = System.Collections.ArrayList.ReadOnly(new System.Collections.ArrayList(infos.Files(dir, true)));
version = infos.GetVersion();
generation = infos.GetGeneration();
isOptimized = infos.Count == 1 && !infos.Info(0).HasDeletions();
}
示例13: DecRef
internal void DecRef(SegmentInfos segmentInfos)
{
System.Collections.Generic.IEnumerator<string> it = segmentInfos.Files(directory, false).GetEnumerator();
while (it.MoveNext())
{
DecRef(it.Current);
}
}
示例14: ReaderCommit
internal ReaderCommit(SegmentInfos infos, Directory dir)
{
SegmentsFileName_Renamed = infos.SegmentsFileName;
this.Dir = dir;
UserData_Renamed = infos.UserData;
Files = infos.Files(dir, true);
Generation_Renamed = infos.Generation;
SegmentCount_Renamed = infos.Size();
}
示例15: IncRef
internal void IncRef(SegmentInfos segmentInfos, bool isCommit)
{
// If this is a commit point, also incRef the
// segments_N file:
System.Collections.Generic.IEnumerator<string> it = segmentInfos.Files(directory, isCommit).GetEnumerator();
while (it.MoveNext())
{
IncRef(it.Current);
}
}