/** * Build XML for an add command * * @param Query\Command\Add $command * @param UpdateQuery $query * @return string */ public function buildAddXml($command, $query = null) { $xml = '<add'; $xml .= $this->boolAttrib('overwrite', $command->getOverwrite()); $xml .= $this->attrib('commitWithin', $command->getCommitWithin()); $xml .= '>'; foreach ($command->getDocuments() as $doc) { $xml .= '<doc'; $xml .= $this->attrib('boost', $doc->getBoost()); $xml .= '>'; foreach ($doc->getFields() as $name => $value) { $boost = $doc->getFieldBoost($name); $modifier = $doc->getFieldModifier($name); if (is_array($value)) { foreach ($value as $multival) { $xml .= $this->buildFieldXml($name, $boost, $multival, $modifier, $query); } } else { $xml .= $this->buildFieldXml($name, $boost, $value, $modifier, $query); } } $version = $doc->getVersion(); if ($version !== null) { $xml .= $this->buildFieldXml('_version_', null, $version); } $xml .= '</doc>'; } $xml .= '</add>'; return $xml; }