本文整理汇总了C#中Lucene.Net.Store.Directory.FileExists方法的典型用法代码示例。如果您正苦于以下问题:C# Lucene.Net.Store.Directory.FileExists方法的具体用法?C# Lucene.Net.Store.Directory.FileExists怎么用?C# Lucene.Net.Store.Directory.FileExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Store.Directory
的用法示例。
在下文中一共展示了Lucene.Net.Store.Directory.FileExists方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TermVectorsReader
/*internal*/
public TermVectorsReader(Directory d, System.String segment, FieldInfos fieldInfos)
{
if (d.FileExists(segment + TermVectorsWriter.TVX_EXTENSION))
{
tvx = d.OpenInput(segment + TermVectorsWriter.TVX_EXTENSION);
CheckValidFormat(tvx);
tvd = d.OpenInput(segment + TermVectorsWriter.TVD_EXTENSION);
tvdFormat = CheckValidFormat(tvd);
tvf = d.OpenInput(segment + TermVectorsWriter.TVF_EXTENSION);
tvfFormat = CheckValidFormat(tvf);
size = (int) tvx.Length() / 8;
}
this.fieldInfos = fieldInfos;
}
示例2: VectorsReader
public override TermVectorsReader VectorsReader(Directory directory, SegmentInfo segmentInfo, FieldInfos fieldInfos, IOContext context)
{
string fileName = IndexFileNames.SegmentFileName(Lucene3xSegmentInfoFormat.GetDocStoreSegment(segmentInfo), "", Lucene3xTermVectorsReader.VECTORS_FIELDS_EXTENSION);
// Unfortunately, for 3.x indices, each segment's
// FieldInfos can lie about hasVectors (claim it's true
// when really it's false).... so we have to carefully
// check if the files really exist before trying to open
// them (4.x has fixed this):
bool exists;
if (Lucene3xSegmentInfoFormat.GetDocStoreOffset(segmentInfo) != -1 && Lucene3xSegmentInfoFormat.GetDocStoreIsCompoundFile(segmentInfo))
{
string cfxFileName = IndexFileNames.SegmentFileName(Lucene3xSegmentInfoFormat.GetDocStoreSegment(segmentInfo), "", Lucene3xCodec.COMPOUND_FILE_STORE_EXTENSION);
if (segmentInfo.Dir.FileExists(cfxFileName))
{
Directory cfsDir = new CompoundFileDirectory(segmentInfo.Dir, cfxFileName, context, false);
try
{
exists = cfsDir.FileExists(fileName);
}
finally
{
cfsDir.Dispose();
}
}
else
{
exists = false;
}
}
else
{
exists = directory.FileExists(fileName);
}
if (!exists)
{
// 3x's FieldInfos sometimes lies and claims a segment
// has vectors when it doesn't:
return null;
}
else
{
return new Lucene3xTermVectorsReader(directory, segmentInfo, fieldInfos, context);
}
}
示例3: TermVectorsReader
internal TermVectorsReader(Directory d, System.String segment, FieldInfos fieldInfos, int readBufferSize, int docStoreOffset, int size)
{
bool success = false;
try
{
if (d.FileExists(segment + "." + IndexFileNames.VECTORS_INDEX_EXTENSION))
{
tvx = d.OpenInput(segment + "." + IndexFileNames.VECTORS_INDEX_EXTENSION, readBufferSize);
CheckValidFormat(tvx);
tvd = d.OpenInput(segment + "." + IndexFileNames.VECTORS_DOCUMENTS_EXTENSION, readBufferSize);
tvdFormat = CheckValidFormat(tvd);
tvf = d.OpenInput(segment + "." + IndexFileNames.VECTORS_FIELDS_EXTENSION, readBufferSize);
tvfFormat = CheckValidFormat(tvf);
if (- 1 == docStoreOffset)
{
this.docStoreOffset = 0;
this.size = (int) (tvx.Length() >> 3);
}
else
{
this.docStoreOffset = docStoreOffset;
this.size = size;
// Verify the file is long enough to hold all of our
// docs
System.Diagnostics.Debug.Assert(((int) (tvx.Length() / 8)) >= size + docStoreOffset);
}
}
this.fieldInfos = fieldInfos;
success = true;
}
finally
{
// With lock-less commits, it's entirely possible (and
// fine) to hit a FileNotFound exception above. In
// this case, we want to explicitly close any subset
// of things that were opened so that we don't have to
// wait for a GC to do so.
if (!success)
{
Close();
}
}
}
示例4: SlowFileExists
/// <summary>
/// Returns true if the file exists (can be opened), false
/// if it cannot be opened, and (unlike Java's
/// File.exists) if there's some
/// unexpected error.
/// </summary>
public static bool SlowFileExists(Directory dir, string fileName)
{
return dir.FileExists(fileName);
/*try
{
dir.OpenInput(fileName, IOContext.DEFAULT).Dispose();
return true;
}
catch (FileNotFoundException e)
{
return false;
}*/
}
示例5: IndexExists
/// <summary> Returns <code>true</code> if an index exists at the specified directory.
/// If the directory does not exist or if there is no index in it.
/// </summary>
/// <param name="directory">the directory to check for an index
/// </param>
/// <returns> <code>true</code> if an index exists; <code>false</code> otherwise
/// </returns>
/// <throws> IOException if there is a problem with accessing the index </throws>
public static bool IndexExists(Directory directory)
{
return directory.FileExists(IndexFileNames.SEGMENTS);
}
示例6: TermVectorsReader
internal TermVectorsReader(Directory d, System.String segment, FieldInfos fieldInfos, int readBufferSize, int docStoreOffset, int size)
{
bool success = false;
try
{
if (d.FileExists(segment + "." + IndexFileNames.VECTORS_INDEX_EXTENSION))
{
tvx = d.OpenInput(segment + "." + IndexFileNames.VECTORS_INDEX_EXTENSION, readBufferSize);
format = CheckValidFormat(tvx);
tvd = d.OpenInput(segment + "." + IndexFileNames.VECTORS_DOCUMENTS_EXTENSION, readBufferSize);
int tvdFormat = CheckValidFormat(tvd);
tvf = d.OpenInput(segment + "." + IndexFileNames.VECTORS_FIELDS_EXTENSION, readBufferSize);
int tvfFormat = CheckValidFormat(tvf);
System.Diagnostics.Debug.Assert(format == tvdFormat);
System.Diagnostics.Debug.Assert(format == tvfFormat);
if (format >= FORMAT_VERSION2)
{
System.Diagnostics.Debug.Assert((tvx.Length() - FORMAT_SIZE) % 16 == 0);
numTotalDocs = (int)(tvx.Length() >> 4);
}
else
{
System.Diagnostics.Debug.Assert((tvx.Length() - FORMAT_SIZE) % 8 == 0);
numTotalDocs = (int)(tvx.Length() >> 3);
}
if (-1 == docStoreOffset)
{
this.docStoreOffset = 0;
this.size = numTotalDocs;
System.Diagnostics.Debug.Assert(size == 0 || numTotalDocs == size);
}
else
{
this.docStoreOffset = docStoreOffset;
this.size = size;
// Verify the file is long enough to hold all of our
// docs
System.Diagnostics.Debug.Assert(numTotalDocs >= size + docStoreOffset, "numTotalDocs=" + numTotalDocs + " size=" + size + " docStoreOffset=" + docStoreOffset);
}
}
else
{
// If all documents flushed in a segment had hit
// non-aborting exceptions, it's possible that
// FieldInfos.hasVectors returns true yet the term
// vector files don't exist.
format = 0;
}
this.fieldInfos = fieldInfos;
success = true;
}
finally
{
// With lock-less commits, it's entirely possible (and
// fine) to hit a FileNotFound exception above. In
// this case, we want to explicitly close any subset
// of things that were opened so that we don't have to
// wait for a GC to do so.
if (!success)
{
Close();
}
}
}
示例7: CachedIndexInput
public CachedIndexInput( ICloudProvider CloudProvider, Directory CacheDirectory, string Name )
{
this.name = Name;
#if FULLDEBUG
Debug.WriteLine( "Opening " + this.name );
#endif
this.fileMutex = BlobMutexManager.GrabMutex( this.name );
this.fileMutex.WaitOne();
try {
bool fFileNeeded = false;
FileMetadata cloudMetadata = CloudProvider.FileMetadata( this.name );
if ( !cloudMetadata.Exists ) {
fFileNeeded = false;
// TODO: Delete local if it doesn't exist on cloud?
/*
if (CacheDirectory.FileExists(this.name)) {
CacheDirectory.DeleteFile(this.name);
}
*/
} else if ( !CacheDirectory.FileExists( this.name ) ) {
fFileNeeded = true;
} else {
long cachedLength = CacheDirectory.FileLength( this.name );
long blobLength = cloudMetadata.Length;
DateTime blobLastModifiedUTC = cloudMetadata.LastModified.ToUniversalTime();
if ( !cloudMetadata.Exists || cachedLength != blobLength ) {
fFileNeeded = true;
} else {
// there seems to be an error of 1 tick which happens every once in a while
// for now we will say that if they are within 1 tick of each other and same length
DateTime cachedLastModifiedUTC = new DateTime( CacheDirectory.FileModified( this.name ), DateTimeKind.Local ).ToUniversalTime();
if ( cachedLastModifiedUTC < blobLastModifiedUTC ) {
TimeSpan timeSpan = blobLastModifiedUTC.Subtract( cachedLastModifiedUTC );
if ( timeSpan.TotalSeconds > 1 ) {
fFileNeeded = true;
} else {
#if FULLDEBUG
Debug.WriteLine( "Using cache for " + this.name + ": " + timeSpan.TotalSeconds );
#endif
// file not needed
}
}
}
}
// if the file does not exist
// or if it exists and it is older then the lastmodified time in the blobproperties (which always comes from the blob storage)
if ( fFileNeeded ) {
using ( StreamOutput fileStream = new StreamOutput( CacheDirectory.CreateOutput( this.name ) ) ) {
Stream blobStream = CloudProvider.Download( this.name );
blobStream.CopyTo( fileStream );
fileStream.Flush();
Debug.WriteLine( "GET {0} RETREIVED {1} bytes", this.name, fileStream.Length );
}
} else {
#if FULLDEBUG
if ( !cloudMetadata.Exists ) {
Debug.WriteLine( "Cloud doesn't have " + this.name );
} else {
Debug.WriteLine( "Using cached file for " + this.name );
}
#endif
}
// open the file in read only mode
this.indexInput = CacheDirectory.OpenInput( this.name );
} finally {
this.fileMutex.ReleaseMutex();
}
}