/** * Get name for new segment * * @return string */ private function _newSegmentName() { Lucene\LockManager::obtainWriteLock($this->_directory); $generation = Lucene\Index::getActualGeneration($this->_directory); $segmentsFile = $this->_directory->getFileObject(Lucene\Index::getSegmentFileName($generation), false); $segmentsFile->seek(12); // 12 = 4 (int, file format marker) + 8 (long, index version) $segmentNameCounter = $segmentsFile->readInt(); $segmentsFile->seek(12); // 12 = 4 (int, file format marker) + 8 (long, index version) $segmentsFile->writeInt($segmentNameCounter + 1); // Flash output to guarantee that wrong value will not be loaded between unlock and // return (which calls $segmentsFile destructor) $segmentsFile->flush(); Lucene\LockManager::releaseWriteLock($this->_directory); return '_' . base_convert($segmentNameCounter, 10, 36); }
/** * Object destructor */ public function __destruct() { $this->commit(); // Release "under processing" flag LockManager::releaseReadLock($this->_directory); if ($this->_closeDirOnExit) { $this->_directory->close(); } $this->_directory = null; $this->_writer = null; $this->_segmentInfos = null; }