PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Storage Containers

The abstract class Zend_Search_Lucene_Storage_Directory defines directory functionality.

The Zend_Search_Lucene constructor uses either a string or a Zend_Search_Lucene_Storage_Directory object as an input.

The Zend_Search_Lucene_Storage_Directory_Filesystem class implements directory functionality for a file system.

If a string is used as an input for the Zend_Search_Lucene constructor, then the index reader (Zend_Search_Lucene object) treats it as a file system path and instantiates the Zend_Search_Lucene_Storage_Directory_Filesystem object.

You can define your own directory implementation by extending the Zend_Search_Lucene_Storage_Directory class.

Zend_Search_Lucene_Storage_Directory methods:

<?php
abstract class Zend_Search_Lucene_Storage_Directory {
/**
 * Closes the store.
 *
 * @return void
 */
abstract function close();

/**
 * Creates a new, empty file in the directory with the given $filename.
 *
 * @param string $name
 * @return void
 */
abstract function createFile($filename);

/**
 * Removes an existing $filename in the directory.
 *
 * @param string $filename
 * @return void
 */
abstract function deleteFile($filename);

/**
 * Returns true if a file with the given $filename exists.
 *
 * @param string $filename
 * @return boolean
 */
abstract function fileExists($filename);

/**
 * Returns the length of a $filename in the directory.
 *
 * @param string $filename
 * @return integer
 */
abstract function fileLength($filename);

/**
 * Returns the UNIX timestamp $filename was last modified.
 *
 * @param string $filename
 * @return integer
 */
abstract function fileModified($filename);

/**
 * Renames an existing file in the directory.
 *
 * @param string $from
 * @param string $to
 * @return void
 */
abstract function renameFile($from$to);

/**
 * Sets the modified time of $filename to now.
 *
 * @param string $filename
 * @return void
 */
abstract function touchFile($filename);

/**
 * Returns a Zend_Search_Lucene_Storage_File object for a given
 * $filename in the directory.
 *
 * @param string $filename
 * @return Zend_Search_Lucene_Storage_File
 */
abstract function getFileObject($filename);

}

The getFileObject($filename) method of a Zend_Search_Lucene_Storage_Directory instance returns a Zend_Search_Lucene_Storage_File object.

The Zend_Search_Lucene_Storage_File abstract class implements file abstraction and index file reading primitives.

You must also extend Zend_Search_Lucene_Storage_File for your directory implementation.

Only two methods of Zend_Search_Lucene_Storage_File must be overridden in your implementation:

<?php
class MyFile extends Zend_Search_Lucene_Storage_File {
    
/**
     * Sets the file position indicator and advances the file pointer.
     * The new position, measured in bytes from the beginning of the file,
     * is obtained by adding offset to the position specified by whence,
     * whose values are defined as follows:
     * SEEK_SET - Set position equal to offset bytes.
     * SEEK_CUR - Set position to current location plus offset.
     * SEEK_END - Set position to end-of-file plus offset. (To move to
     * a position before the end-of-file, you need to pass a negative value
     * in offset.)
     * Upon success, returns 0; otherwise, returns -1
     *
     * @param integer $offset
     * @param integer $whence
     * @return integer
     */
    
public function seek($offset$whence=SEEK_SET) {
        ...
    }

    
/**
     * Read a $length bytes from the file and advance the file pointer.
     *
     * @param integer $length
     * @return string
     */
    
protected function _fread($length=1) {
        ...
    }
}

Zend Framework