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


PHP Zend_Search_Lucene_Storage_Directory::createFile方法代码示例

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


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

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

示例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
     Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);
     // Write down changes for the segments
     foreach ($this->_segmentInfos as $segInfo) {
         $segInfo->writeChanges();
     }
     $generation = Zend_Search_Lucene::getActualGeneration($this->_directory);
     $segmentsFile = $this->_directory->getFileObject(Zend_Search_Lucene::getSegmentFileName($generation), false);
     $newSegmentFile = $this->_directory->createFile(Zend_Search_Lucene::getSegmentFileName(++$generation), false);
     try {
         $genFile = $this->_directory->getFileObject('segments.gen', false);
     } catch (Zend_Search_Lucene_Exception $e) {
         if (strpos($e->getMessage(), 'is not readable') !== false) {
             $genFile = $this->_directory->createFile('segments.gen');
         } else {
             throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
         }
     }
     $genFile->writeInt((int) 0xfffffffe);
     // Write generation (first copy)
     $genFile->writeLong($generation);
     try {
         // Write format marker
         if ($this->_targetFormatVersion == Zend_Search_Lucene::FORMAT_2_1) {
             $newSegmentFile->writeInt((int) 0xfffffffd);
         } else {
             if ($this->_targetFormatVersion == Zend_Search_Lucene::FORMAT_2_3) {
                 $newSegmentFile->writeInt((int) 0xfffffffc);
             }
         }
         // Read src file format identifier
         $format = $segmentsFile->readInt();
         if ($format == (int) 0xffffffff) {
             $srcFormat = Zend_Search_Lucene::FORMAT_PRE_2_1;
         } else {
             if ($format == (int) 0xfffffffd) {
                 $srcFormat = Zend_Search_Lucene::FORMAT_2_1;
             } else {
                 if ($format == (int) 0xfffffffc) {
                     $srcFormat = Zend_Search_Lucene::FORMAT_2_3;
                 } else {
                     throw new Zend_Search_Lucene_Exception('Unsupported segments file format');
                 }
             }
         }
         $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 dummy data (segment counter)
         $newSegmentFile->writeInt(0);
         // Read number of segemnts
         $segmentsCount = $segmentsFile->readInt();
         $segments = array();
         for ($count = 0; $count < $segmentsCount; $count++) {
             $segName = $segmentsFile->readString();
             $segSize = $segmentsFile->readInt();
             if ($srcFormat == Zend_Search_Lucene::FORMAT_PRE_2_1) {
                 // pre-2.1 index format
                 $delGen = 0;
                 $hasSingleNormFile = false;
                 $numField = (int) 0xffffffff;
                 $isCompoundByte = 0;
                 $docStoreOptions = null;
             } else {
                 $delGen = $segmentsFile->readLong();
                 if ($srcFormat == Zend_Search_Lucene::FORMAT_2_3) {
                     $docStoreOffset = $segmentsFile->readInt();
                     if ($docStoreOffset != (int) 0xffffffff) {
                         $docStoreSegment = $segmentsFile->readString();
                         $docStoreIsCompoundFile = $segmentsFile->readByte();
                         $docStoreOptions = array('offset' => $docStoreOffset, 'segment' => $docStoreSegment, 'isCompound' => $docStoreIsCompoundFile == 1);
                     } else {
                         $docStoreOptions = null;
                     }
                 } else {
                     $docStoreOptions = null;
                 }
                 $hasSingleNormFile = $segmentsFile->readByte();
                 $numField = $segmentsFile->readInt();
                 $normGens = array();
                 if ($numField != (int) 0xffffffff) {
                     for ($count1 = 0; $count1 < $numField; $count1++) {
                         $normGens[] = $segmentsFile->readLong();
                     }
                 }
                 $isCompoundByte = $segmentsFile->readByte();
             }
             if (!in_array($segName, $this->_segmentsToDelete)) {
                 // Load segment if necessary
//.........这里部分代码省略.........
开发者ID:Sywooch,项目名称:forums,代码行数:101,代码来源:Writer.php

示例6: 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)
 {
     $lock = $lockDirectory->createFile(self::OPTIMIZATION_LOCK_FILE);
     if (!$lock->lock(LOCK_EX, true)) {
         return false;
     }
     return $lock;
 }
开发者ID:nfouka,项目名称:jobbet_sf2.5,代码行数:16,代码来源:LockManager.php

示例7: _updateSegments

    /**
     * Update segments file by adding current segment to a list
     *
     * @throws Zend_Search_Lucene_Exception
     */
    private function _updateSegments()
    {
        // Get an exclusive index lock
        Zend_Search_Lucene_LockManager::obtainWriteLock($this->_directory);

        $generation = Zend_Search_Lucene::getActualGeneration($this->_directory);
        $segmentsFile   = $this->_directory->getFileObject(Zend_Search_Lucene::getSegmentFileName($generation), false);
        $newSegmentFile = $this->_directory->createFile(Zend_Search_Lucene::getSegmentFileName(++$generation), false);

        try {
            $genFile = $this->_directory->getFileObject('segments.gen', false);
        } catch (Zend_Search_Lucene_Exception $e) {
            if (strpos($e->getMessage(), 'is not readable') !== false) {
                $genFile = $this->_directory->createFile('segments.gen');
            } else {
                throw $e;
            }
        }
        
        $genFile->writeInt((int)0xFFFFFFFE);
        // Write generation (first copy)
        $genFile->writeLong($generation);

        try {
            // Write format marker
            $newSegmentFile->writeInt((int)0xFFFFFFFD);
    
            // Skip format identifier
            $segmentsFile->seek(4, SEEK_CUR);
            // $version = $segmentsFile->readLong() + $this->_versionUpdate;
            // Process version on 32-bit platforms
            $versionHigh = $segmentsFile->readInt();
            $versionLow  = $segmentsFile->readInt();
            $version = $versionHigh * ((double)0xFFFFFFFF + 1) +
                       (($versionLow < 0)? (double)0xFFFFFFFF - (-1 - $versionLow) : $versionLow);
            $version += $this->_versionUpdate;
            $this->_versionUpdate = 0;
            $newSegmentFile->writeInt((int)($version/((double)0xFFFFFFFF + 1)));
            $newSegmentFile->writeInt((int)($version & 0xFFFFFFFF));
    
            // Write segment name counter
            $newSegmentFile->writeInt($segmentsFile->readInt());
    
            // Get number of segments offset
            $numOfSegmentsOffset = $newSegmentFile->tell();
            // Write dummy data (segment counter)
            $newSegmentFile->writeInt(0);
    
            // Read number of segemnts
            $segmentsCount = $segmentsFile->readInt();

            $segments = array();
            for ($count = 0; $count < $segmentsCount; $count++) {
                $segName = $segmentsFile->readString();
                $segSize = $segmentsFile->readInt();
    
                if ($generation == 1 /* retrieved generation is 0 */) {
                    // pre-2.1 index format
                    $delGenHigh = 0;
                    $delGenLow  = 0;
                    $hasSingleNormFile = false;
                    $numField = (int)0xFFFFFFFF;
                    $isCompound = 1;
                } else {
                    //$delGen          = $segmentsFile->readLong();
                    $delGenHigh        = $segmentsFile->readInt();
                    $delGenLow         = $segmentsFile->readInt();
                    $hasSingleNormFile = $segmentsFile->readByte();
                    $numField          = $segmentsFile->readInt();
    
                    $normGens = array();
                    if ($numField != (int)0xFFFFFFFF) {
                        for ($count1 = 0; $count1 < $numField; $count1++) {
                            $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();
                        
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:Writer.php

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

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

示例10: obtainWriteLock

 /**
  * Obtain exclusive write lock on the index
  *
  * @param Zend_Search_Lucene_Storage_Directory $defaultLockDirectory
  * @return Zend_Search_Lucene_Storage_File
  * @throws Zend_Search_Lucene_Exception
  */
 public static function obtainWriteLock(Zend_Search_Lucene_Storage_Directory $defaultLockDirectory)
 {
     $lock = $defaultLockDirectory->createFile('write.lock');
     if (!$lock->lock(LOCK_EX)) {
         throw new Zend_Search_Lucene_Exception('Can\'t obtain exclusive index lock');
     }
     return $lock;
 }
开发者ID:ismaelmelus,项目名称:home,代码行数:15,代码来源:Lucene.php

示例11: 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

示例12: 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

示例13: _updateSegments

 /**
  * Update segments file by adding current segment to a list
  *
  * @throws Zend_Search_Lucene_Exception
  */
 private function _updateSegments()
 {
     // Get an exclusive index lock
     $lock = Zend_Search_Lucene::obtainWriteLock($this->_directory);
     $generation = Zend_Search_Lucene::getActualGeneration($this->_directory);
     $segmentsFile = $this->_directory->getFileObject(Zend_Search_Lucene::getSegmentFileName($generation), false);
     $newSegmentFile = $this->_directory->createFile(Zend_Search_Lucene::getSegmentFileName(++$generation), false);
     try {
         $genFile = $this->_directory->getFileObject('segments.gen', false);
     } catch (Zend_Search_Lucene_Exception $e) {
         if (strpos($e->getMessage(), 'is not readable') !== false) {
             $genFile = $this->_directory->createFile('segments.gen');
         } else {
             throw $e;
         }
     }
     $genFile->writeInt((int) 0xfffffffe);
     // Write generation (first copy)
     $genFile->writeLong($generation);
     try {
         // Write format marker
         $newSegmentFile->writeInt((int) 0xfffffffd);
         // Skip format identifier
         $segmentsFile->seek(4, SEEK_CUR);
         // $version = $segmentsFile->readLong() + $this->_versionUpdate;
         // Process version on 32-bit platforms
         $versionHigh = $segmentsFile->readInt();
         $versionLow = $segmentsFile->readInt();
         $version = $versionHigh * ((double) 0xffffffff + 1) + ($versionLow < 0 ? (double) 0xffffffff - (-1 - $versionLow) : $versionLow);
         $version += $this->_versionUpdate;
         $this->_versionUpdate = 0;
         $newSegmentFile->writeInt((int) ($version / ((double) 0xffffffff + 1)));
         $newSegmentFile->writeInt((int) ($version & 0xffffffff));
         // Write segment name counter
         $newSegmentFile->writeInt($segmentsFile->readInt());
         // Get number of segments offset
         $numOfSegmentsOffset = $newSegmentFile->tell();
         // Write dummy data (segment counter)
         $newSegmentFile->writeInt(0);
         // Read number of segemnts
         $segmentsCount = $segmentsFile->readInt();
         $segments = array();
         for ($count = 0; $count < $segmentsCount; $count++) {
             $segName = $segmentsFile->readString();
             $segSize = $segmentsFile->readInt();
             if ($generation == 1) {
                 // pre-2.1 index format
                 $delGenHigh = 0;
                 $delGenLow = 0;
                 $hasSingleNormFile = false;
                 $numField = (int) 0xffffffff;
                 $isCompound = 1;
             } else {
                 //$delGen          = $segmentsFile->readLong();
                 $delGenHigh = $segmentsFile->readInt();
                 $delGenLow = $segmentsFile->readInt();
                 $hasSingleNormFile = $segmentsFile->readByte();
                 $numField = $segmentsFile->readInt();
                 $normGens = array();
                 if ($numField != (int) 0xffffffff) {
                     for ($count1 = 0; $count1 < $numField; $count1++) {
                         $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;
             }
//.........这里部分代码省略.........
开发者ID:ismaelmelus,项目名称:home,代码行数:101,代码来源:Writer.php


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