Пример #1
0
 /**
  * Generate compound index file
  */
 private 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);
         $cfsFile->writeBytes($dataFile->readBytes($this->_directory->fileLength($fileName)));
         $this->_directory->deleteFile($fileName);
     }
 }
Пример #2
0
 /**
  * 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($segmentsFile->tell() - 20));
     foreach ($this->_newSegments as $segmentName => $segmentInfo) {
         $newSegmentFile->writeString($segmentName);
         $newSegmentFile->writeInt($segmentInfo->count());
     }
     $this->_directory->renameFile('segments.new', 'segments');
 }