Write changes if it's necessary.

This method must be invoked only from the Writer _updateSegments() method,
so index Write lock has to be already obtained.

@internal
@throws Zend_Search_Lucene_Exceptions
559045
public function writeChanges()
    {
        // Get new generation number
        $latestDelGen = $this->_detectLatestDelGen();

        if (!$this->_deletedDirty) {
            // There was no deletions by current process

            if ($latestDelGen == $this->_delGen) {
                // Delete file hasn't been updated by any concurrent process
                return;
            } else if ($latestDelGen > $this->_delGen) {
                // Delete file has been updated by some concurrent process
                // Reload deletions file
                $this->_delGen  = $latestDelGen;
                $this->_deleted = $this->_loadDelFile();

                return;
            } else {
                require_once 'Zend/Search/Lucene/Exception.php';
                throw new Zend_Search_Lucene_Exception('Delete file processing workflow is corrupted for the segment \'' . $this->_name . '\'.');
            }
        }

        if ($latestDelGen > $this->_delGen) {
            // Merge current deletions with latest deletions file
            $this->_delGen = $latestDelGen;

            $latestDelete = $this->_loadDelFile();

            if (extension_loaded('bitset')) {
                $this->_deleted = bitset_union($this->_deleted, $latestDelete);
            } else {
                $this->_deleted += $latestDelete;
            }
        }

        if (extension_loaded('bitset')) {
            $delBytes = $this->_deleted;
            $bitCount = count(bitset_to_array($delBytes));
        } else {
            $byteCount = floor($this->_docCount/8)+1;
            $delBytes = str_repeat(chr(0), $byteCount);
            for ($count = 0; $count < $byteCount; $count++) {
                $byte = 0;
                for ($bit = 0; $bit < 8; $bit++) {
                    if (isset($this->_deleted[$count*8 + $bit])) {
                        $byte |= (1<<$bit);
                    }
                }
                $delBytes[$count] = chr($byte);
            }
            $bitCount = count($this->_deleted);
        }

        if ($this->_delGen == -1) {
            // Set delete file generation number to 1
            $this->_delGen = 1;
        } else {
            // Increase delete file generation number by 1
            $this->_delGen++;
        }

        $delFile = $this->_directory->createFile($this->_name . '_' . base_convert($this->_delGen, 10, 36) . '.del');
        $delFile->writeInt($this->_docCount);
        $delFile->writeInt($bitCount);
        $delFile->writeBytes($delBytes);

        $this->_deletedDirty = false;
    }
253658
public function commit()
    {
    	// Write the changes
        if (is_writable($this->file)) {
            $config = var_export($this->cfg, true);
            file_put_contents($this->file, "<?php return $config ;");

            return true;
        }
        throw new ConfigException("Could not write config file. $file is not writable", 1);
    }
349325
public function flush(): void
    {
        if ($this->writeDocument === true) {
            $this->write($this->getXML());
        }

        parent::flush();
    }
273548
private function writeIndexes()
    {
        //Begin database batch
        $this->beginBatch();

        //Index all node entities
        foreach ($this->nodeEntities as $entity)
        {
            $this->index($entity);
        }

        //Index all relation entities
        foreach ($this->relationEntities as $entity)
        {
            $this->index($entity);
        }

        //Write all repository indexes
        foreach ($this->repositories as $repository)
        {
            $repository->writeIndex();
        }

        //Commit batch to the database
        $this->commitBatch();
    }
1308524
public function rewrite(Zend_Search_Lucene_Interface $index)
    {
        if ($this->_term->field != null) {
            return $this;
        } else {
            include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
            $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
            $query->setBoost($this->getBoost());

            include_once 'Zend/Search/Lucene/Index/Term.php';
            foreach ($index->getFieldNames(true) as $fieldName) {
                $term = new Zend_Search_Lucene_Index_Term($this->_term->text, $fieldName);

                $query->addTerm($term);
            }

            return $query->rewrite($index);
        }
    }
97659
public function merge()
    {
        if ($this->_mergeDone) {
            include_once 'Zend/Search/Lucene/Exception.php';
            throw new Zend_Search_Lucene_Exception('Merge is already done.');
        }

        if (count($this->_segmentInfos) < 1) {
            include_once 'Zend/Search/Lucene/Exception.php';
            throw new Zend_Search_Lucene_Exception(
                'Wrong number of segments to be merged ('
                                                 . count($this->_segmentInfos)
                . ').'
            );
        }

        $this->_mergeFields();
        $this->_mergeNorms();
        $this->_mergeStoredFields();
        $this->_mergeTerms();

        $this->_mergeDone = true;

        return $this->_writer->close();
    }
697242
public void write(BufferedWriter writer) throws Exception {
		Enumeration enm;

		// header
		writer.write("# generated " + new Date());
		writer.newLine();

		enm = elements();

		while (enm.hasMoreElements()) {
			writer.write(enm.nextElement().toString());
			writer.newLine();
		}

		writer.flush();
		writer.close();
	}
1238348
public function commit()
    {
        if ($this->_currentSegment !== null) {
            $newSegment = $this->_currentSegment->close();
            if ($newSegment !== null) {
                $this->_newSegments[$newSegment->getName()] = $newSegment;
            }
            $this->_currentSegment = null;
        }

        $this->_updateSegments();
    }
961402
public function onBeforeWrite()
    {
        parent::onBeforeWrite();
        $owner = $this->owner;
        if (!$owner->ID) {
            // first write
            $owner->updatepresets = true;
        }
    }
265777
public function addTermEntry()
    {
        include_once 'Zend/Search/Lucene/Search/QueryEntry/Term.php';
        $entry = new Zend_Search_Lucene_Search_QueryEntry_Term($this->_currentToken->text, $this->_context->getField());
        $this->_context->addEntry($entry);
    }
95938
protected function write(array $data)
    {
        $changes = $this->getChanges($data);

        $this->syncUpdated($changes['updated']);
        $this->syncInserted($changes['inserted']);
        $this->syncDeleted($changes['deleted']);
    }
517207
public void updateWriter()
    {
        HdfsStreamWriter result = new HdfsStreamWriter();
        String suffix = this.config.getTmpFileSuffix();
        int suffixIndex = 0;
        boolean isFileSyncEachTime = this.config.isFileSyncEachTime();
        boolean isSucceed = false;

        while (suffixIndex < TMP_MAX)
        {
            try
            {
                result.open(this.currentOutputUri + suffix, this.fileSystem, isFileSyncEachTime);
                isSucceed = true;
                break;
            }
            catch (IOException ex)
            {
                String logFormat = "Failed to HDFS file open. Skip and retry next file. : TargetUri={0}";
                String logMessage = MessageFormat.format(logFormat, this.currentOutputUri + suffix);
                logger.warn(logMessage, ex);
                suffixIndex++;
                suffix = this.config.getTmpFileSuffix() + suffixIndex;
            }
        }

        if (isSucceed)
        {
            this.currentWriter = result;
            this.currentSuffix = suffix;
        }
        else
        {
            String logFormat = "HDFS file open failure is retry overed. Skip HDFS file open. : TargetUri={0}";
            String logMessage = MessageFormat.format(logFormat, this.currentOutputUri + suffix);
            logger.warn(logMessage);
        }
    }
877734
public function onAfterWrite() {
		if (!self::$indexing) return;

		// No longer doing the 'ischanged' check to avoid problems with multivalue field NOT being indexed
		//$changes = $this->owner->getChangedFields(true, 2);
			
		$stage = null;
		// if it's being written and a versionable, then save only in the draft
		// repository. 
		if ($this->owner->hasMethod('canBeVersioned') && $this->owner->canBeVersioned($this->owner->baseTable())) {
            $stage = Versioned::current_stage();
		}

		if ($this->canShowInSearch()) {
            // DataObject::write() does _not_ set LastEdited until _after_ onAfterWrite completes
            $this->owner->LastEdited = date('Y-m-d H:i:s');
			$this->reindex($stage);
		}
	}
446648
public function rewrite(Zend_Search_Lucene_Interface $index)
    {
        if (count($this->_terms) == 0) {
            include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
            return new Zend_Search_Lucene_Search_Query_Empty();
        } else if ($this->_terms[0]->field !== null) {
            return $this;
        } else {
            include_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
            $query = new Zend_Search_Lucene_Search_Query_Boolean();
            $query->setBoost($this->getBoost());

            foreach ($index->getFieldNames(true) as $fieldName) {
                $subquery = new Zend_Search_Lucene_Search_Query_Phrase();
                $subquery->setSlop($this->getSlop());

                include_once 'Zend/Search/Lucene/Index/Term.php';
                foreach ($this->_terms as $termId => $term) {
                    $qualifiedTerm = new Zend_Search_Lucene_Index_Term($term->text, $fieldName);

                    $subquery->addTerm($qualifiedTerm, $this->_offsets[$termId]);
                }

                $query->addSubquery($subquery);
            }

            return $query;
        }
    }
253448
public void flushSegmentIndexBuffers() {
        SegmentIndexBuffer sib = null;
        
        while((sib = _sibManager.poll()) != null) {
            File sibFile = getSegmentIndexBufferFile(sib.getSegmentId());
            try {
                _sibManager.getSegmentIndexBufferIO().write(sib, sibFile);
            } catch (Exception e) {
                _log.warn("failed to write " + sibFile.getAbsolutePath());
                sibFile.delete();
            }
        }
    }
1180073
public function rewrite(Zend_Search_Lucene_Interface $index)
    {
        if (count($this->_terms) == 0) {
            include_once 'Zend/Search/Lucene/Search/Query/Empty.php';
            return new Zend_Search_Lucene_Search_Query_Empty();
        }

        // Check, that all fields are qualified
        $allQualified = true;
        foreach ($this->_terms as $term) {
            if ($term->field === null) {
                $allQualified = false;
                break;
            }
        }

        if ($allQualified) {
            return $this;
        } else {
            /**
 * transform multiterm query to boolean and apply rewrite() method to subqueries. 
*/
            include_once 'Zend/Search/Lucene/Search/Query/Boolean.php';
            $query = new Zend_Search_Lucene_Search_Query_Boolean();
            $query->setBoost($this->getBoost());

            include_once 'Zend/Search/Lucene/Search/Query/Term.php';
            foreach ($this->_terms as $termId => $term) {
                $subquery = new Zend_Search_Lucene_Search_Query_Term($term);

                $query->addSubquery(
                    $subquery->rewrite($index),
                    ($this->_signs === null)?  true : $this->_signs[$termId]
                );
            }

            return $query;
        }
    }
528097
protected function write()
	{
		$ww		= new XML_WDDX_FileWriter( $this->fileName );
		foreach( $this->getConfigValues() as $sectionName => $sectionData )
			foreach( $sectionData as $key => $value)
				$ww->add( $key, $value );
		$ww->write();
	}