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


PHP Zend_Search_Lucene_Storage_Directory::fileExists方法代码示例

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


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

示例1: _updateSegments

 /**
  * Update segments file by adding current segment to a list
  *
  * @todo !!!! locks should be processed to prevent concurrent access errors
  *
  * @throws Zend_Search_Lucene_Exception
  */
 private function _updateSegments()
 {
     $segmentsFile = $this->_directory->getFileObject('segments');
     $newSegmentFile = $this->_directory->createFile('segments.new');
     // Write format marker
     $newSegmentFile->writeInt((int) 0xffffffff);
     // Write index version
     $segmentsFile->seek(4, SEEK_CUR);
     $version = $segmentsFile->readLong() + $this->_versionUpdate;
     $this->_versionUpdate = 0;
     $newSegmentFile->writeLong($version);
     // Write segment name counter
     $newSegmentFile->writeInt($segmentsFile->readInt());
     // Write number of segemnts
     $segments = $segmentsFile->readInt();
     $newSegmentFile->writeInt($segments + count($this->_newSegments) - count($this->_segmentsToDelete));
     for ($count = 0; $count < $segments; $count++) {
         $segName = $segmentsFile->readString();
         $segSize = $segmentsFile->readInt();
         if (!array_key_exists($segName, $this->_segmentsToDelete)) {
             $newSegmentFile->writeString($segName);
             $newSegmentFile->writeInt($segSize);
         }
     }
     foreach ($this->_newSegments as $segmentName => $segmentInfo) {
         $newSegmentFile->writeString($segmentName);
         $newSegmentFile->writeInt($segmentInfo->count());
         $this->_segmentInfos[] = $segmentInfo;
     }
     $this->_newSegments = array();
     $fileList = $this->_directory->fileList();
     foreach ($this->_segmentsToDelete as $nameToDelete) {
         foreach ($this->_segmentInfos as $segId => $segInfo) {
             if ($segInfo->getName() == $nameToDelete) {
                 unset($this->_segmentInfos[$segId]);
             }
         }
         foreach (self::$_indexExtensions as $ext) {
             if ($this->_directory->fileExists($nameToDelete . $ext)) {
                 $this->_directory->deleteFile($nameToDelete . $ext);
             }
         }
         foreach ($fileList as $file) {
             if (substr($file, 0, strlen($nameToDelete) + 2) == $nameToDelete . '.f' && ctype_digit(substr($file, strlen($nameToDelete) + 2))) {
                 $this->_directory->deleteFile($file);
             }
         }
     }
     $this->_segmentsToDelete = array();
     $this->_directory->renameFile('segments.new', 'segments');
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:58,代码来源:Writer.php

示例2: _updateSegments

 /**
  * Update segments file by adding current segment to a list
  *
  * @throws Zend_Search_Lucene_Exception
  */
 private function _updateSegments()
 {
     // Get an exclusive index lock
     // Wait, until all parallel searchers or indexers won't stop
     // and stop all next searchers, while we are updating segments file
     $lock = $this->_directory->getFileObject('index.lock');
     if (!$lock->lock(LOCK_EX)) {
         throw new Zend_Search_Lucene_Exception('Can\'t obtain exclusive index lock');
     }
     // Do not share file handlers to get file updates from other sessions.
     $segmentsFile = $this->_directory->getFileObject('segments', false);
     $newSegmentFile = $this->_directory->createFile('segments.new', false);
     // Write format marker
     $newSegmentFile->writeInt((int) 0xffffffff);
     // Write index version
     $segmentsFile->seek(4, SEEK_CUR);
     $version = $segmentsFile->readLong() + $this->_versionUpdate;
     $this->_versionUpdate = 0;
     $newSegmentFile->writeLong($version);
     // Write segment name counter
     $newSegmentFile->writeInt($segmentsFile->readInt());
     // Get number of segments offset
     $numOfSegmentsOffset = $newSegmentFile->tell();
     // Write number of segemnts
     $segmentsCount = $segmentsFile->readInt();
     $newSegmentFile->writeInt(0);
     // Write dummy data (segment counter)
     $segments = array();
     for ($count = 0; $count < $segmentsCount; $count++) {
         $segName = $segmentsFile->readString();
         $segSize = $segmentsFile->readInt();
         if (!in_array($segName, $this->_segmentsToDelete)) {
             $newSegmentFile->writeString($segName);
             $newSegmentFile->writeInt($segSize);
             $segments[$segName] = $segSize;
         }
     }
     $segmentsFile->close();
     $segmentsCount = count($segments) + count($this->_newSegments);
     // Remove segments, not listed in $segments (deleted)
     // Load segments, not listed in $this->_segmentInfos
     foreach ($this->_segmentInfos as $segId => $segInfo) {
         if (isset($segments[$segInfo->getName()])) {
             // Segment is already included into $this->_segmentInfos
             unset($segments[$segInfo->getName()]);
         } else {
             // remove deleted segment from a list
             unset($this->_segmentInfos[$segId]);
         }
     }
     // $segments contains a list of segments to load
     // do it later
     foreach ($this->_newSegments as $segName => $segmentInfo) {
         $newSegmentFile->writeString($segName);
         $newSegmentFile->writeInt($segmentInfo->count());
         $this->_segmentInfos[] = $segmentInfo;
     }
     $this->_newSegments = array();
     $newSegmentFile->seek($numOfSegmentsOffset);
     $newSegmentFile->writeInt($segmentsCount);
     // Update segments count
     $newSegmentFile->close();
     $this->_directory->renameFile('segments.new', 'segments');
     // Segments file update is finished
     // Switch back to shared lock mode
     $lock->lock(LOCK_SH);
     $fileList = $this->_directory->fileList();
     foreach ($this->_segmentsToDelete as $nameToDelete) {
         foreach (self::$_indexExtensions as $ext) {
             if ($this->_directory->fileExists($nameToDelete . $ext)) {
                 $this->_directory->deleteFile($nameToDelete . $ext);
             }
         }
         foreach ($fileList as $file) {
             if (substr($file, 0, strlen($nameToDelete) + 2) == $nameToDelete . '.f' && ctype_digit(substr($file, strlen($nameToDelete) + 2))) {
                 $this->_directory->deleteFile($file);
             }
         }
     }
     $this->_segmentsToDelete = array();
     // Load segments, created by other process
     foreach ($segments as $segName => $segSize) {
         // Load new segments
         $this->_segmentInfos[] = new Zend_Search_Lucene_Index_SegmentInfo($segName, $segSize, $this->_directory);
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:91,代码来源:Writer.php

示例3: obtainOptimizationLock

 /**
  * Obtain exclusive optimization lock on the index
  * 
  * Returns lock object on success and false otherwise (doesn't block execution)
  *
  * @param Zend_Search_Lucene_Storage_Directory $lockDirectory
  * @return mixed
  */
 public static function obtainOptimizationLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
 {
     if ($lockDirectory->fileExists(self::OPTIMIZATION_LOCK_FILE)) {
         return false;
     }
     $lock = $lockDirectory->createFile(self::OPTIMIZATION_LOCK_FILE);
     return $lock;
 }
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:16,代码来源:SoftLockManager.php


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