当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Search_Lucene_Storage_Directory::getFileObject方法代码示例

本文整理汇总了PHP中Zend_Search_Lucene_Storage_Directory::getFileObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Storage_Directory::getFileObject方法的具体用法?PHP Zend_Search_Lucene_Storage_Directory::getFileObject怎么用?PHP Zend_Search_Lucene_Storage_Directory::getFileObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Search_Lucene_Storage_Directory的用法示例。


在下文中一共展示了Zend_Search_Lucene_Storage_Directory::getFileObject方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _generateCFS

 /**
  * Generate compound index file
  */
 protected function _generateCFS()
 {
     $cfsFile = $this->_directory->createFile($this->_name . '.cfs');
     $cfsFile->writeVInt(count($this->_files));
     $dataOffsetPointers = array();
     foreach ($this->_files as $fileName) {
         $dataOffsetPointers[$fileName] = $cfsFile->tell();
         $cfsFile->writeLong(0);
         // write dummy data
         $cfsFile->writeString($fileName);
     }
     foreach ($this->_files as $fileName) {
         // Get actual data offset
         $dataOffset = $cfsFile->tell();
         // Seek to the data offset pointer
         $cfsFile->seek($dataOffsetPointers[$fileName]);
         // Write actual data offset value
         $cfsFile->writeLong($dataOffset);
         // Seek back to the end of file
         $cfsFile->seek($dataOffset);
         $dataFile = $this->_directory->getFileObject($fileName);
         $byteCount = $this->_directory->fileLength($fileName);
         while ($byteCount > 0) {
             $data = $dataFile->readBytes(min($byteCount, 131072));
             $byteCount -= strlen($data);
             $cfsFile->writeBytes($data);
         }
         $this->_directory->deleteFile($fileName);
     }
 }
开发者ID:5haman,项目名称:knowledgetree,代码行数:33,代码来源:SegmentWriter.php

示例2: __construct

 /**
  * Opens the index.
  *
  * IndexReader constructor needs Directory as a parameter. It should be
  * a string with a path to the index folder or a Directory object.
  *
  * @param mixed $directory
  * @throws Zend_Search_Lucene_Exception
  */
 public function __construct($directory = null, $create = false)
 {
     if ($directory === null) {
         throw new Zend_Search_Exception('No index directory specified');
     }
     if ($directory instanceof Zend_Search_Lucene_Storage_Directory_Filesystem) {
         $this->_directory = $directory;
         $this->_closeDirOnExit = false;
     } else {
         $this->_directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($directory);
         $this->_closeDirOnExit = true;
     }
     $this->_segmentInfos = array();
     // Mark index as "under processing" to prevent other processes from premature index cleaning
     Zend_Search_Lucene_LockManager::obtainReadLock($this->_directory);
     // Escalate read lock to prevent current generation index files to be deleted while opening process is not done
     Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory);
     $this->_generation = self::getActualGeneration($this->_directory);
     if ($create) {
         try {
             Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);
         } catch (Zend_Search_Lucene_Exception $e) {
             if (strpos($e->getMessage(), 'Can\'t obtain exclusive index lock') === false) {
                 throw $e;
             } else {
                 throw new Zend_Search_Lucene_Exception('Can\'t create index. It\'s under processing now');
             }
         }
         if ($this->_generation == -1) {
             // Directory doesn't contain existing index, start from 1
             $this->_generation = 1;
             $nameCounter = 0;
         } else {
             // Directory contains existing index
             $segmentsFile = $this->_directory->getFileObject(self::getSegmentFileName($this->_generation));
             $segmentsFile->seek(12);
             // 12 = 4 (int, file format marker) + 8 (long, index version)
             $nameCounter = $segmentsFile->readInt();
             $this->_generation++;
         }
         Zend_Search_Lucene_Index_Writer::createIndex($this->_directory, $this->_generation, $nameCounter);
         Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
     }
     if ($this->_generation == -1) {
         throw new Zend_Search_Lucene_Exception('Index doesn\'t exists in the specified directory.');
     } else {
         if ($this->_generation == 0) {
             $this->_readPre21SegmentsFile();
         } else {
             $this->_readSegmentsFile();
         }
     }
     // De-escalate read lock to prevent current generation index files to be deleted while opening process is not done
     Zend_Search_Lucene_LockManager::deEscalateReadLock($this->_directory);
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:64,代码来源:Lucene.php

示例3: __construct

 /**
  * Opens the index.
  *
  * IndexReader constructor needs Directory as a parameter. It should be
  * a string with a path to the index folder or a Directory object.
  *
  * @param mixed $directory
  * @throws Zend_Search_Lucene_Exception
  */
 public function __construct($directory = null, $create = false)
 {
     if ($directory === null) {
         throw new Zend_Search_Exception('No index directory specified');
     }
     if ($directory instanceof Zend_Search_Lucene_Storage_Directory_Filesystem) {
         $this->_directory = $directory;
         $this->_closeDirOnExit = false;
     } else {
         $this->_directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($directory);
         $this->_closeDirOnExit = true;
     }
     // Get a shared lock to the index
     $this->_lock = $this->_directory->createFile('index.lock');
     $this->_segmentInfos = array();
     if ($create) {
         // Throw an exception if index is under processing now
         if (!$this->_lock->lock(LOCK_EX, true)) {
             throw new Zend_Search_Lucene_Exception('Can\'t create index. It\'s under processing now');
         }
         // Writer will create segments file for empty segments list
         $this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory, $this->_segmentInfos, true);
         if (!$this->_lock->lock(LOCK_SH)) {
             throw new Zend_Search_Lucene_Exception('Can\'t reduce lock level from Exclusive to Shared');
         }
     } else {
         // Wait if index is under switching from one set of segments to another (Index_Writer::_updateSegments())
         if (!$this->_lock->lock(LOCK_SH)) {
             throw new Zend_Search_Lucene_Exception('Can\'t obtain shared index lock');
         }
         $this->_writer = null;
     }
     $segmentsFile = $this->_directory->getFileObject('segments');
     $format = $segmentsFile->readInt();
     if ($format != (int) 0xffffffff) {
         throw new Zend_Search_Lucene_Exception('Wrong segments file format');
     }
     // read version
     // $segmentsFile->readLong();
     $segmentsFile->readInt();
     $segmentsFile->readInt();
     // read segment name counter
     $segmentsFile->readInt();
     $segments = $segmentsFile->readInt();
     $this->_docCount = 0;
     // read segmentInfos
     for ($count = 0; $count < $segments; $count++) {
         $segName = $segmentsFile->readString();
         $segSize = $segmentsFile->readInt();
         $this->_docCount += $segSize;
         $this->_segmentInfos[] = new Zend_Search_Lucene_Index_SegmentInfo($segName, $segSize, $this->_directory);
     }
 }
开发者ID:ookwudili,项目名称:chisimba,代码行数:62,代码来源:Lucene.php

示例4: getActualGeneration

 public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory)
 {
     require_once 'Zend/Search/Lucene/Exception.php';
     try {
         for ($count = 0; $count < self::GENERATION_RETRIEVE_COUNT; $count++) {
             // Try to get generation file
             $genFile = $directory->getFileObject('segments.gen', false);
             $format = $genFile->readInt();
             if ($format != (int) 0xfffffffe) {
                 throw new Zend_Search_Lucene_Exception('Wrong segments.gen file format');
             }
             $gen1 = $genFile->readLong();
             $gen2 = $genFile->readLong();
             if ($gen1 == $gen2) {
                 return $gen1;
             }
             usleep(self::GENERATION_RETRIEVE_PAUSE * 1000);
         }
         // All passes are failed
         throw new Zend_Search_Lucene_Exception('Index is under processing now');
     } catch (Zend_Search_Lucene_Exception $e) {
         if (strpos($e->getMessage(), 'is not readable') !== false) {
             try {
                 // Try to open old style segments file
                 $segmentsFile = $directory->getFileObject('segments', false);
                 // It's pre-2.1 index
                 return 0;
             } catch (Zend_Search_Lucene_Exception $e) {
                 if (strpos($e->getMessage(), 'is not readable') !== false) {
                     return -1;
                 } else {
                     throw $e;
                 }
             }
         } else {
             throw $e;
         }
     }
     return -1;
 }
开发者ID:hackingman,项目名称:TubeX,代码行数:40,代码来源:Lucene.php

示例5: _updateSegments

 /**
  * Update segments file by adding current segment to a list
  * @todo !!!!!Finish the implementation
  *
  * @throws Zend_Search_Lucene_Exception
  */
 private function _updateSegments()
 {
     $segmentsFile = $this->_directory->getFileObject('segments');
     $newSegmentFile = $this->_directory->createFile('segments.new');
     $newSegmentFile->writeInt((int) 0xffffffff);
     $newSegmentFile->writeLong($this->_version);
     $newSegmentFile->writeInt($this->_segmentNameCounter);
     $newSegmentFile->writeInt($this->_segments + count($this->_newSegments));
     $segmentsFile->seek(20);
     $newSegmentFile->writeBytes($segmentsFile->readBytes($this->_directory->fileLength('segments') - 20));
     foreach ($this->_newSegments as $segmentName => $segmentInfo) {
         $newSegmentFile->writeString($segmentName);
         $newSegmentFile->writeInt($segmentInfo->count());
     }
     $this->_directory->renameFile('segments.new', 'segments');
 }
开发者ID:tejdeeps,项目名称:tejcs.com,代码行数:22,代码来源:Writer.php

示例6: _newSegmentName

 /**
  * Get name for new segment
  *
  * @return string
  */
 private function _newSegmentName()
 {
     Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);
     $generation = Zend_Search_Lucene::getActualGeneration($this->_directory);
     $segmentsFile = $this->_directory->getFileObject(Zend_Search_Lucene::getSegmentFileName($generation), false);
     $segmentsFile->seek(12);
     // 12 = 4 (int, file format marker) + 8 (long, index version)
     $segmentNameCounter = $segmentsFile->readInt();
     $segmentsFile->seek(12);
     // 12 = 4 (int, file format marker) + 8 (long, index version)
     $segmentsFile->writeInt($segmentNameCounter + 1);
     // Flash output to guarantee that wrong value will not be loaded between unlock and
     // return (which calls $segmentsFile destructor)
     $segmentsFile->flush();
     Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
     return '_' . base_convert($segmentNameCounter, 10, 36);
 }
开发者ID:Sywooch,项目名称:forums,代码行数:22,代码来源:Writer.php

示例7: __construct

 /**
  * Opens the index.
  *
  * IndexReader constructor needs Directory as a parameter. It should be
  * a string with a path to the index folder or a Directory object.
  *
  * @param mixed $directory
  * @throws Zend_Search_Lucene_Exception
  */
 public function __construct($directory = null, $create = false)
 {
     if ($directory === null) {
         throw new Zend_Search_Exception('No index directory specified');
     }
     if ($directory instanceof Zend_Search_Lucene_Storage_Directory_Filesystem) {
         $this->_directory = $directory;
         $this->_closeDirOnExit = false;
     } else {
         $this->_directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($directory);
         $this->_closeDirOnExit = true;
     }
     if ($create) {
         $this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory, true);
     } else {
         $this->_writer = null;
     }
     $this->_segmentInfos = array();
     $segmentsFile = $this->_directory->getFileObject('segments');
     $format = $segmentsFile->readInt();
     if ($format != (int) 0xffffffff) {
         throw new Zend_Search_Lucene_Exception('Wrong segments file format');
     }
     // read version
     $segmentsFile->readLong();
     // read counter
     $segmentsFile->readInt();
     $segments = $segmentsFile->readInt();
     $this->_docCount = 0;
     // read segmentInfos
     for ($count = 0; $count < $segments; $count++) {
         $segName = $segmentsFile->readString();
         $segSize = $segmentsFile->readInt();
         $this->_docCount += $segSize;
         $this->_segmentInfos[$count] = new Zend_Search_Lucene_Index_SegmentInfo($segName, $segSize, $this->_directory);
     }
 }
开发者ID:tejdeeps,项目名称:tejcs.com,代码行数:46,代码来源:Lucene.php

示例8: releaseOptimizationLock

 /**
  * Release exclusive optimization lock
  *
  * @param Zend_Search_Lucene_Storage_Directory $lockDirectory
  */
 public static function releaseOptimizationLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
 {
     $lock = $lockDirectory->getFileObject(self::OPTIMIZATION_LOCK_FILE);
     $lock->unlock();
 }
开发者ID:nfouka,项目名称:jobbet_sf2.5,代码行数:10,代码来源:LockManager.php

示例9: _newSegmentName

 /**
  * Get name for new segment
  *
  * @return string
  */
 private function _newSegmentName()
 {
     // Do not share file handler to get file updates from other sessions.
     $segmentsFile = $this->_directory->getFileObject('segments', false);
     // Get exclusive segments file lock
     // We have guarantee, that we will not intersect with _updateSegments() call
     // of other process, because it needs exclusive index lock and waits
     // until all other searchers won't stop
     if (!$segmentsFile->lock(LOCK_EX)) {
         throw new Zend_Search_Lucene_Exception('Can\'t obtain exclusive index lock');
     }
     $segmentsFile->seek(12);
     // 12 = 4 (int, file format marker) + 8 (long, index version)
     $segmentNameCounter = $segmentsFile->readInt();
     $segmentsFile->seek(12);
     // 12 = 4 (int, file format marker) + 8 (long, index version)
     $segmentsFile->writeInt($segmentNameCounter + 1);
     // Flash output to guarantee that wrong value will not be loaded between unlock and
     // return (which calls $segmentsFile destructor)
     $segmentsFile->flush();
     $segmentsFile->unlock();
     return '_' . base_convert($segmentNameCounter, 10, 36);
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:28,代码来源:Writer.php

示例10: _newSegmentName

 /**
  * Get name for new segment
  *
  * @return string
  */
 private function _newSegmentName()
 {
     $segmentsFile = $this->_directory->getFileObject('segments');
     $segmentsFile->seek(12);
     // 12 = 4 (int, file format marker) + 8 (long, index version)
     $segmentNameCounter = $segmentsFile->readInt();
     $segmentsFile->seek(12);
     // 12 = 4 (int, file format marker) + 8 (long, index version)
     $segmentsFile->writeInt($segmentNameCounter + 1);
     return '_' . base_convert($segmentNameCounter, 10, 36);
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:16,代码来源:Writer.php

示例11: releaseReadLock

 /**
  * Release shared read lock
  * 
  * @param Zend_Search_Lucene_Storage_Directory $lockDirectory
  */
 public static function releaseReadLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
 {
     // get exclusive operation lock on read lock file.
     if ($lockDirectory->fileExists(self::EXCLUSIVE_READ_LOCK_FILE)) {
         throw new Zend_Search_Lucene_Exception('Can\'t obtain shared reading index lock : read lock operation in progress');
     } else {
         $lock = $lockDirectory->createFile(self::EXCLUSIVE_READ_LOCK_FILE);
     }
     try {
         $lock = $lockDirectory->getFileObject(self::READ_LOCK_FILE, false);
         $accesscounter = $lock->readBytes($lock->size());
         $lock->close();
         $accesscounter--;
         $lockDirectory->deleteFile(self::READ_LOCK_FILE);
         if ($accesscounter > 1) {
             // we have'nt released all locks. Create the file again.
             $lock = $lockDirectory->createFile(self::READ_LOCK_FILE);
             $lock->writeBytes($accesscount);
             $lock->flush();
             $lock->close();
         }
     } catch (Zend_Search_Lucene_Exception $e) {
         $lockDirectory->deleteFile(self::EXCLUSIVE_READ_LOCK_FILE);
         // accept failover here
         // throw new Zend_Search_Lucene_Exception('Can\'t obtain shared reading index lock');
     }
     $lockDirectory->deleteFile(self::EXCLUSIVE_READ_LOCK_FILE);
 }
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:33,代码来源:SoftLockManager.php

示例12: getActualGeneration

 public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory)
 {
     try {
         for ($count = 0; $count < self::GENERATION_RETRIEVE_COUNT; $count++) {
             $genFile = $directory->getFileObject('segments.gen', false);
             $format = $genFile->readInt();
             if ($format != (int) 0xfffffffe) {
                 throw new Zend_Search_Lucene_Exception('Wrong segments.gen file format');
             }
             $gen1 = $genFile->readLong();
             $gen2 = $genFile->readLong();
             if ($gen1 == $gen2) {
                 return $gen1;
             }
             usleep(self::GENERATION_RETRIEVE_PAUSE * 1000);
         }
         throw new Zend_Search_Lucene_Exception('Index is under processing now');
     } catch (Zend_Search_Lucene_Exception $e) {
         if (strpos($e->getMessage(), 'is not readable') !== false) {
             try {
                 $segmentsFile = $directory->getFileObject('segments', false);
                 return 0;
             } catch (Zend_Search_Lucene_Exception $e) {
                 if (strpos($e->getMessage(), 'is not readable') !== false) {
                     return -1;
                 } else {
                     throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
                 }
             }
         } else {
             throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
         }
     }
     return -1;
 }
开发者ID:Blu2z,项目名称:implsk,代码行数:35,代码来源:Zend_Search_Lucene.php


注:本文中的Zend_Search_Lucene_Storage_Directory::getFileObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。