C# Класс Lucene.Net.Store.FSDirectory

Base class for Directory implementations that store index files in the file system. There are currently three core subclasses: SimpleFSDirectory is a straightforward implementation using java.io.RandomAccessFile. However, it has poor concurrent performance (multiple threads will bottleneck) as it synchronizes when multiple threads read from the same file. NIOFSDirectory uses java.nio's FileChannel's positional io when reading to avoid synchronization when reading from the same file. Unfortunately, due to a Windows-only Sun JRE bug this is a poor choice for Windows, but on all other platforms this is the preferred choice. Applications using System.Threading.Thread.Interrupt() or Future#cancel(boolean) (on Java 1.5) should use SimpleFSDirectory instead. See NIOFSDirectory java doc for details. MMapDirectory uses memory-mapped IO when reading. This is a good choice if you have plenty of virtual memory relative to your index size, eg if you are running on a 64 bit JRE, or you are running on a 32 bit JRE but your index sizes are small enough to fit into the virtual memory space. Java has currently the limitation of not being able to unmap files from user code. The files are unmapped, when GC releases the byte buffers. Due to this bug in Sun's JRE, MMapDirectory's IndexInput.Close is unable to close the underlying OS file handle. Only when GC finally collects the underlying objects, which could be quite some time later, will the file handle be closed. This will consume additional transient disk usage: on Windows, attempts to delete or overwrite the files will result in an exception; on other platforms, which typically have a "delete on last close" semantics, while such operations will succeed, the bytes are still consuming space on disk. For many applications this limitation is not a problem (e.g. if you have plenty of disk space, and you don't rely on overwriting files on Windows) but it's still an important limitation to be aware of. This class supplies a (possibly dangerous) workaround mentioned in the bug report, which may fail on non-Sun JVMs. Applications using System.Threading.Thread.Interrupt() or Future#cancel(boolean) (on Java 1.5) should use SimpleFSDirectory instead. See MMapDirectory java doc for details. Unfortunately, because of system peculiarities, there is no single overall best implementation. Therefore, we've added the Open(System.IO.DirectoryInfo) method, to allow Lucene to choose the best FSDirectory implementation given your environment, and the known limitations of each implementation. For users who have no reason to prefer a specific implementation, it's best to simply use FSDirectory.Open(System.IO.DirectoryInfo) . For all others, you should instantiate the desired implementation directly.

The locking implementation is by default NativeFSLockFactory , but can be changed by passing in a custom LockFactory instance.

Наследование: Directory
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
StaleFiles ISet
directory System.IO.DirectoryInfo

Private Properties

Свойство Тип Описание

Открытые методы

Метод Описание
CreateOutput ( string name, IOContext context ) : Lucene.Net.Store.IndexOutput

Creates an IndexOutput for the file with the given name.

DeleteFile ( string name ) : void

Removes an existing file in the directory.

Dispose ( ) : void

Closes the store to future operations.

FileExists ( string name ) : bool

Returns true iff a file with the given name exists.

FileLength ( string name ) : long

Returns the length in bytes of a file in the directory.

ListAll ( ) : string[]

Lists all files (not subdirectories) in the directory.

ListAll ( DirectoryInfo dir ) : string[]

Lists all files (not subdirectories) in the directory. this method never returns null (throws System.IO.IOException instead).

Open ( DirectoryInfo path ) : FSDirectory

Creates an FSDirectory instance, trying to pick the best implementation given the current environment. The directory returned uses the NativeFSLockFactory.

Currently this returns MMapDirectory for most Solaris and Windows 64-bit JREs, NIOFSDirectory for other non-Windows JREs, and SimpleFSDirectory for other JREs on Windows. It is highly recommended that you consult the implementation's documentation for your platform before using this method.

NOTE: this method may suddenly change which implementation is returned from release to release, in the event that higher performance defaults become possible; if the precise implementation is important to your application, please instantiate it directly, instead. For optimal performance you should consider using MMapDirectory on 64 bit JVMs.

See above

Open ( DirectoryInfo path, Lucene.Net.Store.LockFactory lockFactory ) : FSDirectory

Just like #open(File), but allows you to also specify a custom LockFactory.

Sync ( ICollection names ) : void
ToString ( ) : string

For debug output.

Защищенные методы

Метод Описание
EnsureCanWrite ( string name ) : void
FSDirectory ( DirectoryInfo dir ) : System
FSDirectory ( DirectoryInfo path, Lucene.Net.Store.LockFactory lockFactory ) : System

Create a new FSDirectory for the named location (ctor for subclasses).

Fsync ( String name, bool isDir = false ) : void

OnIndexOutputClosed ( Lucene.Net.Store.FSIndexOutput io ) : void

Описание методов

CreateOutput() публичный Метод

Creates an IndexOutput for the file with the given name.
public CreateOutput ( string name, IOContext context ) : Lucene.Net.Store.IndexOutput
name string
context IOContext
Результат Lucene.Net.Store.IndexOutput

DeleteFile() публичный Метод

Removes an existing file in the directory.
public DeleteFile ( string name ) : void
name string
Результат void

Dispose() публичный Метод

Closes the store to future operations.
public Dispose ( ) : void
Результат void

EnsureCanWrite() защищенный Метод

protected EnsureCanWrite ( string name ) : void
name string
Результат void

FSDirectory() защищенный Метод

protected FSDirectory ( DirectoryInfo dir ) : System
dir System.IO.DirectoryInfo
Результат System

FSDirectory() защищенный Метод

Create a new FSDirectory for the named location (ctor for subclasses).
if there is a low-level I/O error
protected FSDirectory ( DirectoryInfo path, Lucene.Net.Store.LockFactory lockFactory ) : System
path System.IO.DirectoryInfo the path of the directory
lockFactory Lucene.Net.Store.LockFactory the lock factory to use, or null for the default /// ();
Результат System

FileExists() публичный Метод

Returns true iff a file with the given name exists.
public FileExists ( string name ) : bool
name string
Результат bool

FileLength() публичный Метод

Returns the length in bytes of a file in the directory.
public FileLength ( string name ) : long
name string
Результат long

Fsync() защищенный Метод

protected Fsync ( String name, bool isDir = false ) : void
name String
isDir bool
Результат void

ListAll() публичный Метод

Lists all files (not subdirectories) in the directory.
public ListAll ( ) : string[]
Результат string[]

ListAll() публичный статический Метод

Lists all files (not subdirectories) in the directory. this method never returns null (throws System.IO.IOException instead).
if the directory /// does not exist, or does exist but is not a /// directory. if list() returns null
public static ListAll ( DirectoryInfo dir ) : string[]
dir System.IO.DirectoryInfo
Результат string[]

OnIndexOutputClosed() защищенный Метод

protected OnIndexOutputClosed ( Lucene.Net.Store.FSIndexOutput io ) : void
io Lucene.Net.Store.FSIndexOutput
Результат void

Open() публичный статический Метод

Creates an FSDirectory instance, trying to pick the best implementation given the current environment. The directory returned uses the NativeFSLockFactory.

Currently this returns MMapDirectory for most Solaris and Windows 64-bit JREs, NIOFSDirectory for other non-Windows JREs, and SimpleFSDirectory for other JREs on Windows. It is highly recommended that you consult the implementation's documentation for your platform before using this method.

NOTE: this method may suddenly change which implementation is returned from release to release, in the event that higher performance defaults become possible; if the precise implementation is important to your application, please instantiate it directly, instead. For optimal performance you should consider using MMapDirectory on 64 bit JVMs.

See above

public static Open ( DirectoryInfo path ) : FSDirectory
path System.IO.DirectoryInfo
Результат FSDirectory

Open() публичный статический Метод

Just like #open(File), but allows you to also specify a custom LockFactory.
public static Open ( DirectoryInfo path, Lucene.Net.Store.LockFactory lockFactory ) : FSDirectory
path System.IO.DirectoryInfo
lockFactory Lucene.Net.Store.LockFactory
Результат FSDirectory

Sync() публичный Метод

public Sync ( ICollection names ) : void
names ICollection
Результат void

ToString() публичный Метод

For debug output.
public ToString ( ) : string
Результат string

Описание свойств

StaleFiles защищенное свойство

protected ISet StaleFiles
Результат ISet

directory защищенное свойство

protected DirectoryInfo,System.IO directory
Результат System.IO.DirectoryInfo