Beispiel #1
0
 /**
  * Zend_Search_Lucene_Index_SegmentInfo constructor
  *
  * @param \Zend\Search\Lucene\Storage\Directory $directory
  * @param string     $name
  * @param integer    $docCount
  * @param integer    $delGen
  * @param array|null $docStoreOptions
  * @param boolean    $hasSingleNormFile
  * @param boolean    $isCompound
  * @throws \Zend\Search\Lucene\Exception\RuntimeException
  */
 public function __construct(Directory $directory, $name, $docCount, $delGen = 0, $docStoreOptions = null, $hasSingleNormFile = false, $isCompound = null)
 {
     $this->_directory = $directory;
     $this->_name = $name;
     $this->_docCount = $docCount;
     if ($docStoreOptions !== null) {
         $this->_usesSharedDocStore = true;
         $this->_sharedDocStoreOptions = $docStoreOptions;
         if ($docStoreOptions['isCompound']) {
             $cfxFile = $this->_directory->getFileObject($docStoreOptions['segment'] . '.cfx');
             $cfxFilesCount = $cfxFile->readVInt();
             $cfxFiles = array();
             $cfxFileSizes = array();
             for ($count = 0; $count < $cfxFilesCount; $count++) {
                 $dataOffset = $cfxFile->readLong();
                 if ($count != 0) {
                     $cfxFileSizes[$fileName] = $dataOffset - end($cfxFiles);
                 }
                 $fileName = $cfxFile->readString();
                 $cfxFiles[$fileName] = $dataOffset;
             }
             if ($count != 0) {
                 $cfxFileSizes[$fileName] = $this->_directory->fileLength($docStoreOptions['segment'] . '.cfx') - $dataOffset;
             }
             $this->_sharedDocStoreOptions['files'] = $cfxFiles;
             $this->_sharedDocStoreOptions['fileSizes'] = $cfxFileSizes;
         }
     }
     $this->_hasSingleNormFile = $hasSingleNormFile;
     $this->_delGen = $delGen;
     $this->_termDictionary = null;
     if ($isCompound !== null) {
         $this->_isCompound = $isCompound;
     } else {
         // It's a pre-2.1 segment or isCompound is set to 'unknown'
         // Detect if segment uses compound file
         try {
             // Try to open compound file
             $this->_directory->getFileObject($name . '.cfs');
             // Compound file is found
             $this->_isCompound = true;
         } catch (Lucene\Exception $e) {
             if (strpos($e->getMessage(), 'is not readable') !== false) {
                 // Compound file is not found or is not readable
                 $this->_isCompound = false;
             } else {
                 throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
             }
         }
     }
     $this->_segFiles = array();
     if ($this->_isCompound) {
         $cfsFile = $this->_directory->getFileObject($name . '.cfs');
         $segFilesCount = $cfsFile->readVInt();
         for ($count = 0; $count < $segFilesCount; $count++) {
             $dataOffset = $cfsFile->readLong();
             if ($count != 0) {
                 $this->_segFileSizes[$fileName] = $dataOffset - end($this->_segFiles);
             }
             $fileName = $cfsFile->readString();
             $this->_segFiles[$fileName] = $dataOffset;
         }
         if ($count != 0) {
             $this->_segFileSizes[$fileName] = $this->_directory->fileLength($name . '.cfs') - $dataOffset;
         }
     }
     $fnmFile = $this->openCompoundFile('.fnm');
     $fieldsCount = $fnmFile->readVInt();
     $fieldNames = array();
     $fieldNums = array();
     $this->_fields = array();
     for ($count = 0; $count < $fieldsCount; $count++) {
         $fieldName = $fnmFile->readString();
         $fieldBits = $fnmFile->readByte();
         $this->_fields[$count] = new FieldInfo($fieldName, $fieldBits & 0x1, $count, $fieldBits & 0x2, $fieldBits & 0x10, $fieldBits & 0x20);
         if ($fieldBits & 0x10) {
             // norms are omitted for the indexed field
             $this->_norms[$count] = str_repeat(chr(Similarity::encodeNorm(1.0)), $docCount);
         }
         $fieldNums[$count] = $count;
         $fieldNames[$count] = $fieldName;
     }
     array_multisort($fieldNames, SORT_ASC, SORT_REGULAR, $fieldNums);
     $this->_fieldsDicPositions = array_flip($fieldNums);
     if ($this->_delGen == -2) {
         // SegmentInfo constructor is invoked from index writer
         // Autodetect current delete file generation number
         $this->_delGen = $this->_detectLatestDelGen();
     }
     // Load deletions
     $this->_deleted = $this->_loadDelFile();
 }