Lucene.Net
3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
|
Base class for Directory implementations that store index files in the file system. There are currently three core subclasses: More...
Inherits Lucene.Net.Store.Directory.
Inherited by Lucene.Net.Store.MMapDirectory, Lucene.Net.Store.NIOFSDirectory, and Lucene.Net.Store.SimpleFSDirectory.
Public Member Functions | |
override System.String[] | ListAll () |
Lists all files (not subdirectories) in the directory. | |
override bool | FileExists (System.String name) |
Returns true iff a file with the given name exists. | |
override long | FileModified (System.String name) |
Returns the time the named file was last modified. | |
override void | TouchFile (System.String name) |
Set the modified time of an existing file to now. | |
override long | FileLength (System.String name) |
Returns the length in bytes of a file in the directory. | |
override void | DeleteFile (System.String name) |
Removes an existing file in the directory. | |
override void | Sync (System.String name) |
Ensure that any writes to this file are moved to stable storage. Lucene uses this to properly commit changes to the index, to prevent a machine/OS crash from corrupting the index. | |
override IndexInput | OpenInput (System.String name) |
Returns a stream reading an existing file. | |
override string | GetLockId () |
Return a string identifier that uniquely differentiates this Directory instance from other Directory instances. This ID should be the same if two Directory instances (even in different JVMs and/or on different machines) are considered "the same index". This is how locking "scopes" to the right index. | |
override System.String | ToString () |
For debug output. | |
Public Member Functions inherited from Lucene.Net.Store.Directory | |
abstract IndexOutput | CreateOutput (System.String name) |
Creates a new, empty file in the directory with the given name. Returns a stream writing this file. | |
virtual IndexInput | OpenInput (System.String name, int bufferSize) |
Returns a stream reading an existing file, with the specified read buffer size. The particular Directory implementation may ignore the buffer size. Currently the only Directory implementations that respect this parameter are FSDirectory and Lucene.Net.Index.CompoundFileReader | |
virtual Lock | MakeLock (System.String name) |
Construct a Lock. | |
virtual void | ClearLock (System.String name) |
Attempt to clear (forcefully unlock and remove) the specified lock. Only call this at a time when you are certain this lock is no longer in use. | |
void | Close () |
void | Dispose () |
Closes the store. | |
virtual void | SetLockFactory (LockFactory lockFactory) |
Set the LockFactory that this Directory instance should use for its locking implementation. Each * instance of LockFactory should only be used for one directory (ie, do not share a single instance across multiple Directories). | |
override string | ToString () |
void | EnsureOpen () |
<throws> AlreadyClosedException if this Directory is closed </throws> | |
Static Public Member Functions | |
static FSDirectory | Open (string path) |
Creates an FSDirectory instance, trying to pick the best implementation given the current environment. The directory returned uses the NativeFSLockFactory. | |
static FSDirectory | Open (System.IO.DirectoryInfo path) |
Creates an FSDirectory instance, trying to pick the best implementation given the current environment. The directory returned uses the NativeFSLockFactory. | |
static FSDirectory | Open (System.IO.DirectoryInfo path, LockFactory lockFactory) |
Just like Open(System.IO.DirectoryInfo), but allows you to also specify a custom LockFactory. | |
static System.String[] | ListAll (System.IO.DirectoryInfo dir) |
Lists all files (not subdirectories) in the directory. This method never returns null (throws System.IO.IOException instead). | |
static long | FileModified (System.IO.FileInfo directory, System.String name) |
Returns the time the named file was last modified. | |
Static Public Member Functions inherited from Lucene.Net.Store.Directory | |
static void | Copy (Directory src, Directory dest, bool closeDirSrc) |
Copy contents of a directory src to a directory dest. If a file in src already exists in dest then the one in dest will be blindly overwritten. | |
Static Public Attributes | |
static readonly int | DEFAULT_READ_CHUNK_SIZE = Constants.JRE_IS_64BIT ? int.MaxValue: 100 * 1024 * 1024 |
Default read chunk size. This is a conditional default: on 32bit JVMs, it defaults to 100 MB. On 64bit JVMs, it's Integer.MAX_VALUE . | |
Protected Member Functions | |
override void | Dispose (bool disposing) |
Properties | |
virtual DirectoryInfo | Directory [get] |
int | ReadChunkSize [get, set] |
The maximum number of bytes to read at once from the underlying file during IndexInput.ReadBytes(byte[],int,int). | |
Properties inherited from Lucene.Net.Store.Directory | |
virtual LockFactory | LockFactory [get] |
Get the LockFactory that this Directory instance is using for its locking implementation. Note that this may be null for Directory implementations that provide their own locking implementation. | |
bool | isOpen_ForNUnit [get] |
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.
Definition at line 104 of file FSDirectory.cs.
|
virtual |
Removes an existing file in the directory.
Implements Lucene.Net.Store.Directory.
Definition at line 374 of file FSDirectory.cs.
|
protectedvirtual |
Implements Lucene.Net.Store.Directory.
Definition at line 470 of file FSDirectory.cs.
|
virtual |
Returns true iff a file with the given name exists.
Implements Lucene.Net.Store.Directory.
Definition at line 335 of file FSDirectory.cs.
|
virtual |
Returns the length in bytes of a file in the directory.
Implements Lucene.Net.Store.Directory.
Definition at line 366 of file FSDirectory.cs.
|
virtual |
Returns the time the named file was last modified.
Implements Lucene.Net.Store.Directory.
Definition at line 343 of file FSDirectory.cs.
|
static |
Returns the time the named file was last modified.
Definition at line 351 of file FSDirectory.cs.
|
virtual |
Return a string identifier that uniquely differentiates this Directory instance from other Directory instances. This ID should be the same if two Directory instances (even in different JVMs and/or on different machines) are considered "the same index". This is how locking "scopes" to the right index.
Reimplemented from Lucene.Net.Store.Directory.
Definition at line 440 of file FSDirectory.cs.
|
static |
Lists all files (not subdirectories) in the directory. This method never returns null (throws System.IO.IOException instead).
<throws> NoSuchDirectoryException if the directory </throws>
does not exist, or does exist but is not a directory.
<throws> IOException if list() returns null </throws>
Definition at line 297 of file FSDirectory.cs.
|
virtual |
Lists all files (not subdirectories) in the directory.
Implements Lucene.Net.Store.Directory.
Definition at line 328 of file FSDirectory.cs.
|
static |
Creates an FSDirectory instance, trying to pick the best implementation given the current environment. The directory returned uses the NativeFSLockFactory.
Currently this returns SimpleFSDirectory as NIOFSDirectory is currently not supported.
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. On 64 bit systems, it may also good to return MMapDirectory, but this is disabled because of officially missing unmap support in Java. For optimal performance you should consider using this implementation on 64 bit JVMs.
See above
Definition at line 234 of file FSDirectory.cs.
|
static |
Creates an FSDirectory instance, trying to pick the best implementation given the current environment. The directory returned uses the NativeFSLockFactory.
Currently this returns SimpleFSDirectory as NIOFSDirectory is currently not supported.
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. On 64 bit systems, it may also good to return MMapDirectory, but this is disabled because of officially missing unmap support in Java. For optimal performance you should consider using this implementation on 64 bit JVMs.
See above
Definition at line 259 of file FSDirectory.cs.
|
static |
Just like Open(System.IO.DirectoryInfo), but allows you to also specify a custom LockFactory.
Definition at line 267 of file FSDirectory.cs.
|
virtual |
Returns a stream reading an existing file.
Implements Lucene.Net.Store.Directory.
Definition at line 430 of file FSDirectory.cs.
|
virtual |
Ensure that any writes to this file are moved to stable storage. Lucene uses this to properly commit changes to the index, to prevent a machine/OS crash from corrupting the index.
Reimplemented from Lucene.Net.Store.Directory.
Definition at line 388 of file FSDirectory.cs.
override System.String Lucene.Net.Store.FSDirectory.ToString | ( | ) |
For debug output.
Definition at line 491 of file FSDirectory.cs.
|
virtual |
Set the modified time of an existing file to now.
Implements Lucene.Net.Store.Directory.
Definition at line 358 of file FSDirectory.cs.
|
static |
Default read chunk size. This is a conditional default: on 32bit JVMs, it defaults to 100 MB. On 64bit JVMs, it's Integer.MAX_VALUE
.
Definition at line 502 of file FSDirectory.cs.
|
get |
Definition at line 482 of file FSDirectory.cs.
|
getset |
The maximum number of bytes to read at once from the underlying file during IndexInput.ReadBytes(byte[],int,int).
Definition at line 513 of file FSDirectory.cs.