Class Directory
A Directory is a flat list of files. Files may be written once, when they are created. Once a file is created it may only be opened for read, or deleted. Random access is permitted both when reading and writing.
.NET's i/o APIs not used directly, but rather all i/o is through this API. This permits things such as:
- implementation of RAM-based indices;
- implementation indices stored in a database;
- implementation of an index as a single file;
Directory locking is implemented by an instance of LockFactory, and can be changed for each Directory instance using SetLockFactory(LockFactory).
Implements
Inherited Members
Namespace: Lucene.Net.Store
Assembly: Lucene.Net.dll
Syntax
public abstract class Directory : IDisposableProperties
| Improve this Doc View SourceLockFactory
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.
Declaration
public abstract LockFactory LockFactory { get; }Property Value
| Type | Description | 
|---|---|
| LockFactory | 
Methods
| Improve this Doc View SourceClearLock(String)
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.
Declaration
public abstract void ClearLock(string name)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | name of the lock to be cleared. | 
Copy(Directory, String, String, IOContext)
Copies the file src to Directory to under the new
file name dest.
If you want to copy the entire source directory to the destination one, you can do so like this:
Directory to; // the directory to copy to
foreach (string file in dir.ListAll()) {
    dir.Copy(to, file, newFile, IOContext.DEFAULT); // newFile can be either file, or a new name
}
NOTE: this method does not check whether dest exist and will
overwrite it if it does.
Declaration
public virtual void Copy(Directory to, string src, string dest, IOContext context)Parameters
| Type | Name | Description | 
|---|---|---|
| Directory | to | |
| System.String | src | |
| System.String | dest | |
| IOContext | context | 
CreateOutput(String, IOContext)
Creates a new, empty file in the directory with the given name. Returns a stream writing this file.
Declaration
public abstract IndexOutput CreateOutput(string name, IOContext context)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | |
| IOContext | context | 
Returns
| Type | Description | 
|---|---|
| IndexOutput | 
CreateSlicer(String, IOContext)
Creates an Directory.IndexInputSlicer for the given file name. Directory.IndexInputSlicer allows other Directory implementations to efficiently open one or more sliced IndexInput instances from a single file handle. The underlying file handle is kept open until the Directory.IndexInputSlicer is closed.
Throws System.IO.FileNotFoundException if the file does not exist.
Declaration
public virtual Directory.IndexInputSlicer CreateSlicer(string name, IOContext context)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | |
| IOContext | context | 
Returns
| Type | Description | 
|---|---|
| Directory.IndexInputSlicer | 
Exceptions
| Type | Condition | 
|---|---|
| System.IO.IOException | if an System.IO.IOException occurs | 
DeleteFile(String)
Removes an existing file in the directory.
Declaration
public abstract void DeleteFile(string name)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | 
Dispose()
Disposes the store.
Declaration
public void Dispose()Dispose(Boolean)
Disposes the store.
Declaration
protected abstract void Dispose(bool disposing)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Boolean | disposing | 
EnsureOpen()
Declaration
protected virtual void EnsureOpen()Exceptions
| Type | Condition | 
|---|---|
| System.ObjectDisposedException | if this Directory is closed | 
FileExists(String)
Returns true iff a file with the given name exists.
Declaration
[Obsolete("this method will be removed in 5.0")]
public abstract bool FileExists(string name)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | 
Returns
| Type | Description | 
|---|---|
| System.Boolean | 
FileLength(String)
Returns the length of a file in the directory. this method follows the following contract:
Declaration
public abstract long FileLength(string name)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | the name of the file for which to return the length. | 
Returns
| Type | Description | 
|---|---|
| System.Int64 | 
Exceptions
| Type | Condition | 
|---|---|
| System.IO.IOException | if there was an IO error while retrieving the file's length. | 
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 AppDomains and/or on different machines) are considered "the same index". This is how locking "scopes" to the right index.
Declaration
public virtual string GetLockID()Returns
| Type | Description | 
|---|---|
| System.String | 
ListAll()
Returns an array of strings, one for each file in the directory.
Declaration
public abstract string[] ListAll()Returns
| Type | Description | 
|---|---|
| System.String[] | 
Exceptions
| Type | Condition | 
|---|---|
| System.IO.DirectoryNotFoundException | if the directory is not prepared for any write operations (such as CreateOutput(String, IOContext)). | 
| System.IO.IOException | in case of other IO errors | 
MakeLock(String)
Construct a Lock.
Declaration
public abstract Lock MakeLock(string name)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | the name of the lock file | 
Returns
| Type | Description | 
|---|---|
| Lock | 
OpenChecksumInput(String, IOContext)
Returns a stream reading an existing file, computing checksum as it reads
Declaration
public virtual ChecksumIndexInput OpenChecksumInput(string name, IOContext context)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | |
| IOContext | context | 
Returns
| Type | Description | 
|---|---|
| ChecksumIndexInput | 
OpenInput(String, IOContext)
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 CompoundFileDirectory.
Throws System.IO.FileNotFoundException if the file does not exist.
Declaration
public abstract IndexInput OpenInput(string name, IOContext context)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | name | |
| IOContext | context | 
Returns
| Type | Description | 
|---|---|
| IndexInput | 
SetLockFactory(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).
Declaration
public abstract void SetLockFactory(LockFactory lockFactory)Parameters
| Type | Name | Description | 
|---|---|---|
| LockFactory | lockFactory | instance of LockFactory. | 
Sync(ICollection<String>)
Ensure that any writes to these files 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.
NOTE: Clients may call this method for same files over
and over again, so some impls might optimize for that.
For other impls the operation can be a noop, for various
reasons.
Declaration
public abstract void Sync(ICollection<string> names)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Collections.Generic.ICollection<System.String> | names | 
ToString()
Declaration
public override string ToString()Returns
| Type | Description | 
|---|---|
| System.String |