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


PHP Zend_Search_Lucene_Storage_Directory::fileList方法代码示例

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


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

示例1: createIndex

 public static function createIndex(Zend_Search_Lucene_Storage_Directory $directory, $generation, $nameCount)
 {
     if ($generation == 0) {
         // Create index in pre-2.1 mode
         foreach ($directory->fileList() as $file) {
             if ($file == 'deletable' || $file == 'segments' || isset(self::$_indexExtensions[substr($file, strlen($file) - 4)]) || preg_match('/\\.f\\d+$/i', $file)) {
                 $directory->deleteFile($file);
             }
         }
         $segmentsFile = $directory->createFile('segments');
         $segmentsFile->writeInt((int) 0xffffffff);
         // write version (is initialized by current time
         // $segmentsFile->writeLong((int)microtime(true));
         $version = microtime(true);
         $segmentsFile->writeInt((int) ($version / ((double) 0xffffffff + 1)));
         $segmentsFile->writeInt((int) ($version & 0xffffffff));
         // write name counter
         $segmentsFile->writeInt($nameCount);
         // write segment counter
         $segmentsFile->writeInt(0);
         $deletableFile = $directory->createFile('deletable');
         // write counter
         $deletableFile->writeInt(0);
     } else {
         $genFile = $directory->createFile('segments.gen');
         $genFile->writeInt((int) 0xfffffffe);
         // Write generation two times
         $genFile->writeLong($generation);
         $genFile->writeLong($generation);
         $segmentsFile = $directory->createFile(Zend_Search_Lucene::getSegmentFileName($generation));
         $segmentsFile->writeInt((int) 0xfffffffd);
         // write version (is initialized by current time
         // $segmentsFile->writeLong((int)microtime(true));
         $version = microtime(true);
         $segmentsFile->writeInt((int) ($version / ((double) 0xffffffff + 1)));
         $segmentsFile->writeInt((int) ($version & 0xffffffff));
         // write name counter
         $segmentsFile->writeInt($nameCount);
         // write segment counter
         $segmentsFile->writeInt(0);
     }
 }
开发者ID:hackingman,项目名称:TubeX,代码行数:42,代码来源:Writer.php

示例2: __construct

 /**
  * Opens the index for writing
  *
  * IndexWriter constructor needs Directory as a parameter. It should be
  * a string with a path to the index folder or a Directory object.
  * Second constructor parameter create is optional - true to create the
  * index or overwrite the existing one.
  *
  * @param Zend_Search_Lucene_Storage_Directory $directory
  * @param boolean $create
  */
 public function __construct(Zend_Search_Lucene_Storage_Directory $directory, $create = false)
 {
     $this->_directory = $directory;
     if ($create) {
         foreach ($this->_directory->fileList() as $file) {
             if ($file == 'deletable' || $file == 'segments' || isset(self::$_indexExtensions[substr($file, strlen($file) - 4)]) || preg_match('/\\.f\\d+$/i', $file)) {
                 $this->_directory->deleteFile($file);
             }
         }
         $segmentsFile = $this->_directory->createFile('segments');
         $segmentsFile->writeInt((int) 0xffffffff);
         // write version
         $segmentsFile->writeLong(0);
         // write name counter
         $segmentsFile->writeInt(0);
         // write segment counter
         $segmentsFile->writeInt(0);
         $deletableFile = $this->_directory->createFile('deletable');
         // write counter
         $deletableFile->writeInt(0);
         $this->_version = 0;
         $this->_segmentNameCounter = 0;
         $this->_segments = 0;
     } else {
         $segmentsFile = $this->_directory->getFileObject('segments');
         $format = $segmentsFile->readInt();
         if ($format != (int) 0xffffffff) {
             throw new Zend_Search_Lucene_Exception('Wrong segments file format');
         }
         // read version
         $this->_version = $segmentsFile->readLong();
         // read counter
         $this->_segmentNameCounter = $segmentsFile->readInt();
         // read segment counter
         $this->_segments = $segmentsFile->readInt();
     }
     $this->_newSegments = array();
     $this->_currentSegment = null;
 }
开发者ID:BackupTheBerlios,项目名称:umlrecord,代码行数:50,代码来源:Writer.php

示例3: _updateSegments


//.........这里部分代码省略.........
         $this->_newSegments = array();
         $newSegmentFile->seek($numOfSegmentsOffset);
         $newSegmentFile->writeInt($segmentsCount);
         // Update segments count
         $newSegmentFile->close();
     } catch (Exception $e) {
         /** Restore previous index generation */
         $generation--;
         $genFile->seek(4, SEEK_SET);
         // Write generation number twice
         $genFile->writeLong($generation);
         $genFile->writeLong($generation);
         // Release index write lock
         Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
         // Throw the exception
         require_once 'Zend/Search/Lucene/Exception.php';
         throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
     }
     // Write generation (second copy)
     $genFile->writeLong($generation);
     // Check if another update or read process is not running now
     // If yes, skip clean-up procedure
     if (Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory)) {
         /**
          * Clean-up directory
          */
         $filesToDelete = array();
         $filesTypes = array();
         $filesNumbers = array();
         // list of .del files of currently used segments
         // each segment can have several generations of .del files
         // only last should not be deleted
         $delFiles = array();
         foreach ($this->_directory->fileList() as $file) {
             if ($file == 'deletable') {
                 // 'deletable' file
                 $filesToDelete[] = $file;
                 $filesTypes[] = 0;
                 // delete this file first, since it's not used starting from Lucene v2.1
                 $filesNumbers[] = 0;
             } else {
                 if ($file == 'segments') {
                     // 'segments' file
                     $filesToDelete[] = $file;
                     $filesTypes[] = 1;
                     // second file to be deleted "zero" version of segments file (Lucene pre-2.1)
                     $filesNumbers[] = 0;
                 } else {
                     if (preg_match('/^segments_[a-zA-Z0-9]+$/i', $file)) {
                         // 'segments_xxx' file
                         // Check if it's not a just created generation file
                         if ($file != Zend_Search_Lucene::getSegmentFileName($generation)) {
                             $filesToDelete[] = $file;
                             $filesTypes[] = 2;
                             // first group of files for deletions
                             $filesNumbers[] = (int) base_convert(substr($file, 9), 36, 10);
                             // ordered by segment generation numbers
                         }
                     } else {
                         if (preg_match('/(^_([a-zA-Z0-9]+))\\.f\\d+$/i', $file, $matches)) {
                             // one of per segment files ('<segment_name>.f<decimal_number>')
                             // Check if it's not one of the segments in the current segments set
                             if (!isset($segments[$matches[1]])) {
                                 $filesToDelete[] = $file;
                                 $filesTypes[] = 3;
                                 // second group of files for deletions
开发者ID:Sywooch,项目名称:forums,代码行数:67,代码来源:Writer.php

示例4: _updateSegments


//.........这里部分代码省略.........
        } catch (Exception $e) {
            /** Restore previous index generation */
            $generation--;
            $genFile->seek(4, SEEK_SET);
            // Write generation number twice
            $genFile->writeLong($generation); $genFile->writeLong($generation);

            // Release index write lock
            Zend_Search_Lucene_LockManager::releaseWriteLock($this->_directory);
            
            // Throw the exception
            throw $e;
        }

        // Write generation (second copy)
        $genFile->writeLong($generation);

        
        // Check if another update process is not running now
        // If yes, skip clean-up procedure
        if (Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory)) {
            /**
             * Clean-up directory
             */
            $filesToDelete = array();
            $filesTypes    = array();
            $filesNumbers  = array();
            
            // list of .del files of currently used segments
            // each segment can have several generations of .del files
            // only last should not be deleted
            $delFiles = array();
            
            foreach ($this->_directory->fileList() as $file) {
                if ($file == 'deletable') {
                    // 'deletable' file
                    $filesToDelete[] = $file;
                    $filesTypes[]    = 0; // delete this file first, since it's not used starting from Lucene v2.1
                    $filesNumbers[]  = 0;
                } else if ($file == 'segments') {
                    // 'segments' file
    
                    $filesToDelete[] = $file;
                    $filesTypes[]    = 1; // second file to be deleted "zero" version of segments file (Lucene pre-2.1)
                    $filesNumbers[]  = 0;
                } else if (preg_match('/^segments_[a-zA-Z0-9]+$/i', $file)) {
                    // 'segments_xxx' file
                    // Check if it's not a just created generation file
                    if ($file != Zend_Search_Lucene::getSegmentFileName($generation)) {
                        $filesToDelete[] = $file;
                        $filesTypes[]    = 2; // first group of files for deletions
                        $filesNumbers[]  = (int)base_convert(substr($file, 9), 36, 10); // ordered by segment generation numbers 
                    }
                } else if (preg_match('/(^_([a-zA-Z0-9]+))\.f\d+$/i', $file, $matches)) {
                    // one of per segment files ('<segment_name>.f<decimal_number>')
                    // Check if it's not one of the segments in the current segments set
                    if (!isset($segments[$matches[1]])) {
                        $filesToDelete[] = $file;
                        $filesTypes[]    = 3; // second group of files for deletions
                        $filesNumbers[]  = (int)base_convert($matches[2], 36, 10); // order by segment number 
                    }
                } else if (preg_match('/(^_([a-zA-Z0-9]+))(_([a-zA-Z0-9]+))\.del$/i', $file, $matches)) {
                    // one of per segment files ('<segment_name>_<del_generation>.del' where <segment_name> is '_<segment_number>')
                    // Check if it's not one of the segments in the current segments set
                    if (!isset($segments[$matches[1]])) {
                        $filesToDelete[] = $file;
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:67,代码来源:Writer.php

示例5: _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

示例6: _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

示例7: createIndex

 public static function createIndex(Zend_Search_Lucene_Storage_Directory $directory, $generation, $nameCount)
 {
     if ($generation == 0) {
         foreach ($directory->fileList() as $file) {
             if ($file == 'deletable' || $file == 'segments' || isset(self::$_indexExtensions[substr($file, strlen($file) - 4)]) || preg_match('/\\.f\\d+$/i', $file)) {
                 $directory->deleteFile($file);
             }
         }
         $segmentsFile = $directory->createFile('segments');
         $segmentsFile->writeInt((int) 0xffffffff);
         $segmentsFile->writeLong(round(microtime(true)));
         $segmentsFile->writeInt($nameCount);
         $segmentsFile->writeInt(0);
         $deletableFile = $directory->createFile('deletable');
         $deletableFile->writeInt(0);
     } else {
         $genFile = $directory->createFile('segments.gen');
         $genFile->writeInt((int) 0xfffffffe);
         $genFile->writeLong($generation);
         $genFile->writeLong($generation);
         $segmentsFile = $directory->createFile(Zend_Search_Lucene::getSegmentFileName($generation));
         $segmentsFile->writeInt((int) 0xfffffffd);
         $segmentsFile->writeLong(round(microtime(true)));
         $segmentsFile->writeInt($nameCount);
         $segmentsFile->writeInt(0);
     }
 }
开发者ID:Blu2z,项目名称:implsk,代码行数:27,代码来源:Zend_Search_Lucene.php

示例8: _updateSegments


//.........这里部分代码省略.........
                         $normGens[] = $segmentsFile->readLong();
                     }
                 }
                 $isCompound = $segmentsFile->readByte();
             }
             if (!in_array($segName, $this->_segmentsToDelete)) {
                 // Load segment if necessary
                 if (!isset($this->_segmentInfos[$segName])) {
                     $delGen = $delGenHigh * ((double) 0xffffffff + 1) + ($delGenLow < 0 ? (double) 0xffffffff - (-1 - $delGenLow) : $delGenLow);
                     $this->_segmentInfos[$segName] = new Zend_Search_Lucene_Index_SegmentInfo($this->_directory, $segName, $segSize, $delGen, $hasSingleNormFile, $isCompound);
                 } else {
                     // Retrieve actual detetions file generation number
                     $delGen = $this->_segmentInfos[$segName]->getDelGen();
                     if ($delGen >= 0) {
                         $delGenHigh = (int) ($delGen / ((double) 0xffffffff + 1));
                         $delGenLow = (int) ($delGen & 0xffffffff);
                     } else {
                         $delGenHigh = $delGenLow = (int) 0xffffffff;
                     }
                 }
                 $newSegmentFile->writeString($segName);
                 $newSegmentFile->writeInt($segSize);
                 $newSegmentFile->writeInt($delGenHigh);
                 $newSegmentFile->writeInt($delGenLow);
                 $newSegmentFile->writeByte($hasSingleNormFile);
                 $newSegmentFile->writeInt($numField);
                 if ($numField != (int) 0xffffffff) {
                     foreach ($normGens as $normGen) {
                         $newSegmentFile->writeLong($normGen);
                     }
                 }
                 $newSegmentFile->writeByte($isCompound);
                 $segments[$segName] = $segSize;
             }
         }
         $segmentsFile->close();
         $segmentsCount = count($segments) + count($this->_newSegments);
         foreach ($this->_newSegments as $segName => $segmentInfo) {
             $newSegmentFile->writeString($segName);
             $newSegmentFile->writeInt($segmentInfo->count());
             // delete file generation: -1 (there is no delete file yet)
             $newSegmentFile->writeInt((int) 0xffffffff);
             $newSegmentFile->writeInt((int) 0xffffffff);
             // HasSingleNormFile
             $newSegmentFile->writeByte($segmentInfo->hasSingleNormFile());
             // NumField
             $newSegmentFile->writeInt((int) 0xffffffff);
             // IsCompoundFile
             $newSegmentFile->writeByte($segmentInfo->isCompound());
             $segments[$segmentInfo->getName()] = $segmentInfo->count();
             $this->_segmentInfos[$segName] = $segmentInfo;
         }
         $this->_newSegments = array();
         $newSegmentFile->seek($numOfSegmentsOffset);
         $newSegmentFile->writeInt($segmentsCount);
         // Update segments count
         $newSegmentFile->close();
         // Clean-up directory
         foreach ($this->_directory->fileList() as $file) {
             if ($file == 'deletable' || $file == 'segments' || isset(self::$_indexExtensions[substr($file, strlen($file) - 4)]) || preg_match('/^segments_[a-zA-Z0-9]+$/i', $file) || preg_match('/\\.f\\d+$/i', $file)) {
                 // check, that file is not used by current index generation
                 if ($file == Zend_Search_Lucene::getSegmentFileName($generation) || isset($segments[substr($file, 0, strlen($file) - 4)]) || isset($segments[substr($file, 0, strpos($file, '.f'))]) || substr($file, strlen($file) - 4) == '.del') {
                     continue;
                 }
                 try {
                     $this->_directory->deleteFile($file);
                 } catch (Zend_Search_Lucene_Exception $e) {
                     if (strpos($e->getMessage(), 'Can\'t delete file') === 0) {
                         // File is under processing
                         // Stop clean-up process
                         break;
                     } else {
                         throw $e;
                     }
                 }
             }
         }
     } catch (Exception $e) {
         /** Restore previous index generation */
         $generation--;
         $genFile->seek(4, SEEK_SET);
         // Write generation number twice
         $genFile->writeLong($generation);
         $genFile->writeLong($generation);
         // Release index write lock
         Zend_Search_Lucene::releaseWriteLock($this->_directory, $lock);
         // Throw the exception
         throw $e;
     }
     // Write generation (second copy)
     $genFile->writeLong($generation);
     // Release index write lock
     Zend_Search_Lucene::releaseWriteLock($this->_directory, $lock);
     // Remove unused segments from segments list
     foreach ($this->_segmentInfos as $segName => $segmentInfo) {
         if (!isset($segments[$segName])) {
             unset($this->_segmentInfos[$segName]);
         }
     }
 }
开发者ID:ismaelmelus,项目名称:home,代码行数:101,代码来源:Writer.php


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