Exemplo n.º 1
0
 /**
  * Build XML for an add command
  *
  * @param Solarium_Query_Update_Command_Add $command
  * @return string
  */
 public function buildAddXml($command)
 {
     $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 instanceof Solarium_Document_AtomicUpdate ? $doc->getModifierForField($name) : null;
             if (is_array($value)) {
                 foreach ($value as $multival) {
                     $xml .= $this->_buildFieldXml($name, $boost, $multival, $modifier);
                 }
             } else {
                 $xml .= $this->_buildFieldXml($name, $boost, $value, $modifier);
             }
         }
         $xml .= '</doc>';
     }
     $xml .= '</add>';
     return $xml;
 }
Exemplo n.º 2
0
 /**
  * Convenience method to add a 'add documents' command
  *
  * If you need more control, like choosing a key for the command you need to
  * create you own command instance and use the add method.
  *
  * @param array $documents
  * @param boolean $overwrite
  * @param int $commitWithin
  * @return Solarium_Query_Update Provides fluent interface
  */
 public function addDocuments($documents, $overwrite = null, $commitWithin = null)
 {
     $add = new Solarium_Query_Update_Command_Add();
     if (null !== $overwrite) {
         $add->setOverwrite($overwrite);
     }
     if (null !== $commitWithin) {
         $add->setCommitWithin($commitWithin);
     }
     $add->addDocuments($documents);
     return $this->add(null, $add);
 }
Exemplo n.º 3
0
 public function testBuildAddXmlMultipleDocuments()
 {
     $command = new Solarium_Query_Update_Command_Add();
     $command->addDocument(new Solarium_Document_ReadWrite(array('id' => 1)));
     $command->addDocument(new Solarium_Document_ReadWrite(array('id' => 2)));
     $this->assertEquals('<add><doc><field name="id">1</field></doc><doc><field name="id">2</field></doc></add>', $this->_builder->buildAddXml($command));
 }
Exemplo n.º 4
0
 /**
  * Build XML for an add command
  *
  * @param Solarium_Query_Update_Command_Add $command
  * @return string
  */
 public function buildAddXml($command)
 {
     $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);
             if (is_array($value)) {
                 foreach ($value as $multival) {
                     $xml .= $this->_buildFieldXml($name, $boost, $multival);
                 }
             } else {
                 $xml .= $this->_buildFieldXml($name, $boost, $value);
             }
         }
         $xml .= '</doc>';
     }
     $xml .= '</add>';
     return $xml;
 }