public function testCreate() { $directory = new \Zend\Search\Lucene\Storage\Directory\Filesystem(__DIR__ . '/_source/_files'); $stiFile = $directory->getFileObject('_1.sti'); $stiFileData = $stiFile->readBytes($directory->fileLength('_1.sti')); // Load dictionary index data list($termDictionary, $termDictionaryInfos) = unserialize($stiFileData); $segmentInfo = new \Zend\Search\Lucene\Index\SegmentInfo($directory, '_1', 2); $tiiFile = $segmentInfo->openCompoundFile('.tii'); $tiiFileData = $tiiFile->readBytes($segmentInfo->compoundFileLength('.tii')); // Load dictionary index data list($loadedTermDictionary, $loadedTermDictionaryInfos) = \Zend\Search\Lucene\Index\DictionaryLoader::load($tiiFileData); $this->assertTrue($termDictionary == $loadedTermDictionary); $this->assertTrue($termDictionaryInfos == $loadedTermDictionaryInfos); }
/** * Load terms dictionary index * * @throws \Zend\Search\Lucene\Exception */ private function _loadDictionaryIndex() { // Check, if index is already serialized if ($this->_directory->fileExists($this->_name . '.sti')) { // Load serialized dictionary index data $stiFile = $this->_directory->getFileObject($this->_name . '.sti'); $stiFileData = $stiFile->readBytes($this->_directory->fileLength($this->_name . '.sti')); // Load dictionary index data if (($unserializedData = @unserialize($stiFileData)) !== false) { list($this->_termDictionary, $this->_termDictionaryInfos) = $unserializedData; return; } } // Load data from .tii file and generate .sti file // Prefetch dictionary index data $tiiFile = $this->openCompoundFile('.tii'); $tiiFileData = $tiiFile->readBytes($this->compoundFileLength('.tii')); // Load dictionary index data list($this->_termDictionary, $this->_termDictionaryInfos) = DictionaryLoader::load($tiiFileData); $stiFileData = serialize(array($this->_termDictionary, $this->_termDictionaryInfos)); $stiFile = $this->_directory->createFile($this->_name . '.sti'); $stiFile->writeBytes($stiFileData); }