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


Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
Lucene::FSDirectory Class Reference

Base class for Directory implementations that store index files in the file system. There are currently three core subclasses: More...

#include <FSDirectory.h>

+ Inheritance diagram for Lucene::FSDirectory:

Public Member Functions

virtual ~FSDirectory ()
 
virtual String getClassName ()
 
boost::shared_ptr< FSDirectoryshared_from_this ()
 
void createDir ()
 Create file system directory.
 
String getFile ()
 Return file system directory.
 
void setReadChunkSize (int32_t chunkSize)
 Sets the maximum number of bytes read at once from the underlying file during IndexInput#readBytes. The default value is DEFAULT_READ_CHUNK_SIZE. Changes to this value will not impact any already-opened IndexInputs. You should call this before attempting to open an index on the directory. This value should be as large as possible to reduce any possible performance impact.
 
int32_t getReadChunkSize ()
 The maximum number of bytes to read at once from the underlying file during IndexInput#readBytes.
 
virtual HashSet< String > listAll ()
 Lists all files (not subdirectories) in the directory.
 
virtual bool fileExists (const String &name)
 Returns true if a file with the given name exists.
 
virtual uint64_t fileModified (const String &name)
 Returns the time the named file was last modified.
 
virtual void touchFile (const String &name)
 Set the modified time of an existing file to now.
 
virtual void deleteFile (const String &name)
 Removes an existing file in the directory.
 
virtual int64_t fileLength (const String &name)
 Returns the length in bytes of a file in the directory.
 
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.
 
virtual IndexInputPtr openInput (const String &name)
 Returns a stream reading an existing file, with the specified read buffer size. The particular Directory implementation may ignore the buffer size.
 
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.
 
virtual String getLockID ()
 Return a string identifier that uniquely differentiates this Directory instance from other Directory instances.
 
virtual void close ()
 Closes the store to future operations.
 
virtual String toString ()
 For debug output.
 
- Public Member Functions inherited from Lucene::Directory
 Directory ()
 
virtual ~Directory ()
 
boost::shared_ptr< Directoryshared_from_this ()
 
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.
 
virtual LockPtr makeLock (const String &name)
 Construct a Lock.
 
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.
 
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).
 
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.
 
- 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.
 
virtual LuceneObjectPtr clone (const LuceneObjectPtr &other=LuceneObjectPtr())
 Return clone of this object.
 
virtual int32_t hashCode ()
 Return hash code for this object.
 
virtual bool equals (const LuceneObjectPtr &other)
 Return whether two objects are equal.
 
virtual int32_t compareTo (const LuceneObjectPtr &other)
 Compare two objects.
 
- Public Member Functions inherited from Lucene::LuceneSync
virtual ~LuceneSync ()
 
virtual SynchronizePtr getSync ()
 Return this object synchronize lock.
 
virtual LuceneSignalPtr getSignal ()
 Return this object signal.
 
virtual void lock (int32_t timeout=0)
 Lock this object using an optional timeout.
 
virtual void unlock ()
 Unlock this object.
 
virtual bool holdsLock ()
 Returns true if this object is currently locked by current thread.
 
virtual void wait (int32_t timeout=0)
 Wait for signal using an optional timeout.
 
virtual void notifyAll ()
 Notify all threads waiting for signal.
 

Static Public Member Functions

static String _getClassName ()
 
static FSDirectoryPtr open (const String &path)
 Creates an FSDirectory instance.
 
static FSDirectoryPtr open (const String &path, const LockFactoryPtr &lockFactory)
 Just like open(File), but allows you to also specify a custom LockFactory.
 
static HashSet< String > listAll (const String &dir)
 Lists all files (not subdirectories) in the directory.
 
static uint64_t fileModified (const String &directory, const String &name)
 Returns the time the named file was last modified.
 
- Static Public Member Functions inherited from Lucene::Directory
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.
 

Static Public Attributes

static const int32_t DEFAULT_READ_CHUNK_SIZE
 Default read chunk size. This is a conditional default based on operating system.
 

Protected Member Functions

 FSDirectory (const String &path, const LockFactoryPtr &lockFactory)
 Create a new FSDirectory for the named location (ctor for subclasses).
 
void initOutput (const String &name)
 Initializes the directory to create a new file with the given name. This method should be used in createOutput.
 
- Protected Member Functions inherited from Lucene::Directory
void ensureOpen ()
 
- Protected Member Functions inherited from Lucene::LuceneObject
 LuceneObject ()
 

Protected Attributes

bool checked
 
String directory
 The underlying filesystem directory.
 
int32_t chunkSize
 
- Protected Attributes inherited from Lucene::Directory
bool isOpen
 
LockFactoryPtr lockFactory
 Holds the LockFactory instance (implements locking for this Directory instance).
 
- Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr objectLock
 
LuceneSignalPtr objectSignal
 

Detailed Description

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 std::ofstream and std::ifstream.

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 operating system, oryour index sizes are small enough to fit into the virtual memory space.

For users who have no reason to prefer a specific implementation, it's best to simply use open. 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.

See also
Directory

Constructor & Destructor Documentation

◆ FSDirectory()

Lucene::FSDirectory::FSDirectory ( const String &  path,
const LockFactoryPtr lockFactory 
)
protected

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

Parameters
paththe path of the directory.
lockFactorythe lock factory to use, or null for the default (NativeFSLockFactory)

◆ ~FSDirectory()

virtual Lucene::FSDirectory::~FSDirectory ( )
virtual

Member Function Documentation

◆ _getClassName()

static String Lucene::FSDirectory::_getClassName ( )
inlinestatic

◆ close()

virtual void Lucene::FSDirectory::close ( )
virtual

Closes the store to future operations.

Implements Lucene::Directory.

◆ createDir()

void Lucene::FSDirectory::createDir ( )

Create file system directory.

◆ deleteFile()

virtual void Lucene::FSDirectory::deleteFile ( const String &  name)
virtual

Removes an existing file in the directory.

Implements Lucene::Directory.

◆ fileExists()

virtual bool Lucene::FSDirectory::fileExists ( const String &  name)
virtual

Returns true if a file with the given name exists.

Implements Lucene::Directory.

◆ fileLength()

virtual int64_t Lucene::FSDirectory::fileLength ( const String &  name)
virtual

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

Implements Lucene::Directory.

◆ fileModified() [1/2]

static uint64_t Lucene::FSDirectory::fileModified ( const String &  directory,
const String &  name 
)
static

Returns the time the named file was last modified.

◆ fileModified() [2/2]

virtual uint64_t Lucene::FSDirectory::fileModified ( const String &  name)
virtual

Returns the time the named file was last modified.

Implements Lucene::Directory.

◆ getClassName()

virtual String Lucene::FSDirectory::getClassName ( )
inlinevirtual

Reimplemented from Lucene::Directory.

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

◆ getFile()

String Lucene::FSDirectory::getFile ( )

Return file system directory.

◆ getLockID()

virtual String Lucene::FSDirectory::getLockID ( )
virtual

Return a string identifier that uniquely differentiates this Directory instance from other Directory instances.

Reimplemented from Lucene::Directory.

◆ getReadChunkSize()

int32_t Lucene::FSDirectory::getReadChunkSize ( )

The maximum number of bytes to read at once from the underlying file during IndexInput#readBytes.

See also
setReadChunkSize

◆ initOutput()

void Lucene::FSDirectory::initOutput ( const String &  name)
protected

Initializes the directory to create a new file with the given name. This method should be used in createOutput.

◆ listAll() [1/2]

virtual HashSet< String > Lucene::FSDirectory::listAll ( )
virtual

Lists all files (not subdirectories) in the directory.

See also
listAll(const String&)

Implements Lucene::Directory.

◆ listAll() [2/2]

static HashSet< String > Lucene::FSDirectory::listAll ( const String &  dir)
static

Lists all files (not subdirectories) in the directory.

Exceptions
NoSuchDirectoryExceptionif the directory does not exist, or does exist but is not a directory.

◆ open() [1/2]

static FSDirectoryPtr Lucene::FSDirectory::open ( const String &  path)
static

Creates an FSDirectory instance.

◆ open() [2/2]

static FSDirectoryPtr Lucene::FSDirectory::open ( const String &  path,
const LockFactoryPtr lockFactory 
)
static

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

◆ openInput() [1/2]

virtual IndexInputPtr Lucene::FSDirectory::openInput ( const String &  name)
virtual

Returns a stream reading an existing file, with the specified read buffer size. The particular Directory implementation may ignore the buffer size.

Implements Lucene::Directory.

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

◆ openInput() [2/2]

virtual IndexInputPtr Lucene::FSDirectory::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 from Lucene::Directory.

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

◆ setReadChunkSize()

void Lucene::FSDirectory::setReadChunkSize ( int32_t  chunkSize)

Sets the maximum number of bytes read at once from the underlying file during IndexInput#readBytes. The default value is DEFAULT_READ_CHUNK_SIZE. Changes to this value will not impact any already-opened IndexInputs. You should call this before attempting to open an index on the directory. This value should be as large as possible to reduce any possible performance impact.

◆ shared_from_this()

boost::shared_ptr< FSDirectory > Lucene::FSDirectory::shared_from_this ( )
inline

◆ sync()

virtual void Lucene::FSDirectory::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 from Lucene::Directory.

◆ toString()

virtual String Lucene::FSDirectory::toString ( )
virtual

For debug output.

Reimplemented from Lucene::Directory.

◆ touchFile()

virtual void Lucene::FSDirectory::touchFile ( const String &  name)
virtual

Set the modified time of an existing file to now.

Implements Lucene::Directory.

Field Documentation

◆ checked

bool Lucene::FSDirectory::checked
protected

◆ chunkSize

int32_t Lucene::FSDirectory::chunkSize
protected

◆ DEFAULT_READ_CHUNK_SIZE

const int32_t Lucene::FSDirectory::DEFAULT_READ_CHUNK_SIZE
static

Default read chunk size. This is a conditional default based on operating system.

See also
setReadChunkSize

◆ directory

String Lucene::FSDirectory::directory
protected

The underlying filesystem directory.


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

clucene.sourceforge.net