Fork me on GitHub
  • API

    Show / Hide Table of Contents

    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).
    Inheritance
    object
    Directory
    BaseDirectory
    FilterDirectory
    Implements
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Lucene.Net.Store
    Assembly: Lucene.Net.dll
    Syntax
    public abstract class Directory : IDisposable

    Properties

    LockFactory

    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

    ClearLock(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
    string name

    name of the lock to be cleared.

    Copy(Directory, string, string, IOContext)

    Copies the file src to Directoryto 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
    string src
    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
    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 FileNotFoundException if the file does not exist.

    Note

    This API is for internal purposes only and might change in incompatible ways in the next release.

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Declaration
    public virtual Directory.IndexInputSlicer CreateSlicer(string name, IOContext context)
    Parameters
    Type Name Description
    string name
    IOContext context
    Returns
    Type Description
    Directory.IndexInputSlicer
    Exceptions
    Type Condition
    IOException

    if an IOException occurs

    DeleteFile(string)

    Removes an existing file in the directory.

    Declaration
    public abstract void DeleteFile(string name)
    Parameters
    Type Name Description
    string name

    Dispose()

    Disposes the store.

    Declaration
    public void Dispose()

    Dispose(bool)

    Disposes the store.

    Declaration
    protected abstract void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

    EnsureOpen()

    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).
    Declaration
    protected virtual void EnsureOpen()
    Exceptions
    Type Condition
    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
    string name
    Returns
    Type Description
    bool

    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
    string name

    the name of the file for which to return the length.

    Returns
    Type Description
    long
    Exceptions
    Type Condition
    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
    string

    ListAll()

    Returns an array of strings, one for each file in the directory.

    Declaration
    public abstract string[] ListAll()
    Returns
    Type Description
    string[]
    Exceptions
    Type Condition
    DirectoryNotFoundException

    if the directory is not prepared for any write operations (such as CreateOutput(string, IOContext)).

    IOException

    in case of other IO errors

    MakeLock(string)

    Construct a Lock.

    Declaration
    public abstract Lock MakeLock(string name)
    Parameters
    Type Name Description
    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
    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 FileNotFoundException if the file does not exist.
    Declaration
    public abstract IndexInput OpenInput(string name, IOContext context)
    Parameters
    Type Name Description
    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
    ICollection<string> names

    ToString()

    Returns a string that represents the current object.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    A string that represents the current object.

    Overrides
    object.ToString()

    Implements

    IDisposable
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.