Lucene++ - a full-featured, c++ search engine
API Documentation

Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
Lucene::Directory Class Referenceabstract

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. Directory locking is implemented by an instance of LockFactory, and can be changed for each Directory instance using setLockFactory. More...

`#include <Directory.h>`

Inheritance diagram for Lucene::Directory:

## Public Member Functions

| Directory ()
virtual | ~Directory ()
virtual String | getClassName ()
boost::shared_ptr< Directory > | shared_from_this ()
virtual HashSet< String > | listAll ()=0
| Returns an array of strings, one for each file in the directory. More...
virtual bool | fileExists (const String &name)=0
| Returns true if a file with the given name exists. More...
virtual uint64_t | fileModified (const String &name)=0
| Returns the time the named file was last modified. More...
virtual void | touchFile (const String &name)=0
| Set the modified time of an existing file to now. More...
virtual void | deleteFile (const String &name)=0
| Removes an existing file in the directory. More...
virtual int64_t | fileLength (const String &name)=0
| Returns the length of a file in the directory. More...
virtual IndexOutputPtr | createOutput (const String &name)=0
| Creates a new, empty file in the directory with the given name. Returns a stream writing this file. More...
virtual IndexInputPtr | openInput (const String &name)=0
| Returns a stream reading an existing file. More...
virtual void | close ()=0
| Closes the store. More...
virtual void | sync (const 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. More...
virtual IndexInputPtr | openInput (const String &name, int32_t 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 CompoundFileReader. More...
virtual LockPtr | makeLock (const String &name)
| Construct a Lock. More...
void | clearLock (const 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. More...
void | setLockFactory (const LockFactoryPtr &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). More...
LockFactoryPtr | getLockFactory ()
| 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. More...
virtual 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 are considered "the same index". This is how locking "scopes" to the right index. More...
virtual String | toString ()
| Returns a string representation of the object. More...
Public Member Functions inherited from Lucene::LuceneObject
virtual | ~LuceneObject ()
virtual void | initialize ()
| Called directly after instantiation to create objects that depend on this object being fully constructed. More...
virtual LuceneObjectPtr | clone (const LuceneObjectPtr &other=LuceneObjectPtr())
| Return clone of this object. More...
virtual int32_t | hashCode ()
| Return hash code for this object. More...
virtual bool | equals (const LuceneObjectPtr &other)
| Return whether two objects are equal. More...
virtual int32_t | compareTo (const LuceneObjectPtr &other)
| Compare two objects. More...
Public Member Functions inherited from Lucene::LuceneSync
virtual | ~LuceneSync ()
virtual SynchronizePtr | getSync ()
| Return this object synchronize lock. More...
virtual LuceneSignalPtr | getSignal ()
| Return this object signal. More...
virtual void | lock (int32_t timeout=0)
| Lock this object using an optional timeout. More...
virtual void | unlock ()
| Unlock this object. More...
virtual bool | holdsLock ()
| Returns true if this object is currently locked by current thread. More...
virtual void | wait (int32_t timeout=0)
| Wait for signal using an optional timeout. More...
virtual void | notifyAll ()
| Notify all threads waiting for signal. More...

## Static Public Member Functions

static String | _getClassName ()
static void | copy (const DirectoryPtr &src, const DirectoryPtr &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. NOTE: the source directory cannot change while this method is running. Otherwise the results are undefined. More...

## Protected Member Functions

void | ensureOpen ()
Protected Member Functions inherited from Lucene::LuceneObject
| LuceneObject ()

## Protected Attributes

bool | isOpen
LockFactoryPtr | lockFactory
| Holds the LockFactory instance (implements locking for this Directory instance). More...
Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr | objectLock
LuceneSignalPtr | objectSignal

## Detailed Description

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. Directory locking is implemented by an instance of LockFactory, and can be changed for each Directory instance using setLockFactory.

## Constructor & Destructor Documentation

## ◆ Directory()

Lucene::Directory::Directory | ( |  | ) |

## ◆ ~Directory()

virtual Lucene::Directory::~Directory | ( |  | ) |

virtual

## Member Function Documentation

## ◆ _getClassName()

static String Lucene::Directory::_getClassName | ( |  | ) |

inline static

## ◆ clearLock()

void Lucene::Directory::clearLock | ( | const 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.

Parameters

  name | name of the lock to be cleared.

## ◆ close()

virtual void Lucene::Directory::close | ( |  | ) |

pure virtual

Closes the store.

Implemented in Lucene::FSDirectory, Lucene::RAMDirectory, Lucene::CompoundFileReader, and Lucene::FileSwitchDirectory.

## ◆ copy()

static void Lucene::Directory::copy | ( | const DirectoryPtr & | src,
|  | const DirectoryPtr & | dest,
|  | bool | closeDirSrc
| ) |  |

static

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. NOTE: the source directory cannot change while this method is running. Otherwise the results are undefined.

Parameters

  src | source directory.
  dest | destination directory.
  closeDirSrc | if true, call close() method on source directory.

## ◆ createOutput()

virtual IndexOutputPtr Lucene::Directory::createOutput | ( | const String & | name | ) |

pure virtual

Creates a new, empty file in the directory with the given name. Returns a stream writing this file.

Implemented in Lucene::CompoundFileReader, Lucene::RAMDirectory, Lucene::FileSwitchDirectory, Lucene::MMapDirectory, and Lucene::SimpleFSDirectory.

## ◆ deleteFile()

virtual void Lucene::Directory::deleteFile | ( | const String & | name | ) |

pure virtual

Removes an existing file in the directory.

Implemented in Lucene::FSDirectory, Lucene::RAMDirectory, Lucene::CompoundFileReader, and Lucene::FileSwitchDirectory.

## ◆ ensureOpen()

void Lucene::Directory::ensureOpen | ( |  | ) |

protected

Exceptions

  AlreadyClosed | if this Directory is closed.

## ◆ fileExists()

virtual bool Lucene::Directory::fileExists | ( | const String & | name | ) |

pure virtual

Returns true if a file with the given name exists.

Implemented in Lucene::FSDirectory, Lucene::CompoundFileReader, Lucene::RAMDirectory, and Lucene::FileSwitchDirectory.

## ◆ fileLength()

virtual int64_t Lucene::Directory::fileLength | ( | const String & | name | ) |

pure virtual

Returns the length of a file in the directory.

Implemented in Lucene::FSDirectory, Lucene::CompoundFileReader, Lucene::RAMDirectory, and Lucene::FileSwitchDirectory.

## ◆ fileModified()

virtual uint64_t Lucene::Directory::fileModified | ( | const String & | name | ) |

pure virtual

Returns the time the named file was last modified.

Implemented in Lucene::FSDirectory, Lucene::CompoundFileReader, Lucene::RAMDirectory, and Lucene::FileSwitchDirectory.

## ◆ getClassName()

virtual String Lucene::Directory::getClassName | ( |  | ) |

inline virtual

Reimplemented in Lucene::FSDirectory, Lucene::RAMDirectory, Lucene::MMapDirectory, Lucene::FileSwitchDirectory, Lucene::CompoundFileReader, and Lucene::SimpleFSDirectory.

## ◆ getLockFactory()

LockFactoryPtr Lucene::Directory::getLockFactory | ( |  | ) |

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.

## ◆ getLockID()

virtual String Lucene::Directory::getLockID | ( |  | ) |

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 are considered "the same index". This is how locking "scopes" to the right index.

Reimplemented in Lucene::FSDirectory.

## ◆ listAll()

virtual HashSet<String> Lucene::Directory::listAll | ( |  | ) |

pure virtual

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

Implemented in Lucene::FSDirectory, Lucene::CompoundFileReader, Lucene::RAMDirectory, and Lucene::FileSwitchDirectory.

## ◆ makeLock()

virtual LockPtr Lucene::Directory::makeLock | ( | const String & | name | ) |

virtual

Construct a Lock.

Parameters

  name | the name of the lock file.

Reimplemented in Lucene::CompoundFileReader.

## ◆ openInput() [1/2]

virtual IndexInputPtr Lucene::Directory::openInput | ( | const String & | name | ) |

pure virtual

Returns a stream reading an existing file.

Implemented in Lucene::FSDirectory, Lucene::RAMDirectory, Lucene::FileSwitchDirectory, Lucene::CompoundFileReader, and Lucene::SimpleFSDirectory.

## ◆ openInput() [2/2]

virtual IndexInputPtr Lucene::Directory::openInput | ( | const String & | name,
|  | int32_t | bufferSize
| ) |  |

virtual

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 CompoundFileReader.

Reimplemented in Lucene::FSDirectory, Lucene::CompoundFileReader, Lucene::MMapDirectory, and Lucene::SimpleFSDirectory.

## ◆ setLockFactory()

void Lucene::Directory::setLockFactory | ( | const LockFactoryPtr & | 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).

Parameters

  lockFactory | instance of LockFactory.

## ◆ shared_from_this()

boost::shared_ptr< Directory > Lucene::Directory::shared_from_this | ( |  | ) |

inline

## ◆ sync()

virtual void Lucene::Directory::sync | ( | const String & | name | ) |

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 in Lucene::FSDirectory, and Lucene::FileSwitchDirectory.

## ◆ toString()

virtual String Lucene::Directory::toString | ( |  | ) |

virtual

Returns a string representation of the object.

Reimplemented from Lucene::LuceneObject.

Reimplemented in Lucene::FSDirectory.

## ◆ touchFile()

virtual void Lucene::Directory::touchFile | ( | const String & | name | ) |

pure virtual

Set the modified time of an existing file to now.

Implemented in Lucene::FSDirectory, Lucene::CompoundFileReader, Lucene::RAMDirectory, and Lucene::FileSwitchDirectory.

## Field Documentation

## ◆ isOpen

bool Lucene::Directory::isOpen

protected

## ◆ lockFactory

LockFactoryPtr Lucene::Directory::lockFactory

protected

Holds the LockFactory instance (implements locking for this Directory instance).

The documentation for this class was generated from the following file:

- Directory.h

clucene.sourceforge.net