Exemple #1
0
 public function testAddAndGetDocuments()
 {
     $doc1 = new ReadOnlyDocument(array('id' => 1));
     $doc2 = new ReadOnlyDocument(array('id' => 2));
     $this->query->addDocuments(array($doc1, $doc2));
     $this->assertEquals(array($doc1, $doc2), $this->query->getDocuments());
 }
 public function testGetRawData()
 {
     // this doc tests data escaping
     $doc1 = new InputDocument(array('id' => 1, 'name' => 'doc1', 'cat' => 'my > cat'));
     // this doc tests a multivalue field
     $doc2 = new InputDocument(array('id' => 2, 'name' => 'doc2', 'cat' => array(1, 2, 3)));
     $this->query->addDocuments(array($doc1, $doc2));
     $this->assertEquals('<docs><doc><field name="id">1</field><field name="name">doc1</field><field name="cat">my &gt; cat</field></doc><doc><field name="id">2</field><field name="name">doc2</field><field name="cat">1</field><field name="cat">2</field><field name="cat">3</field></doc></docs>', $this->builder->getRawData($this->query));
 }
Exemple #3
0
 /**
  * Create the raw post data (xml).
  *
  * @param QueryDocument $query
  *
  * @return string
  */
 public function getRawData($query)
 {
     $xml = '<docs>';
     foreach ($query->getDocuments() as $doc) {
         $xml .= '<doc>';
         foreach ($doc->getFields() as $name => $value) {
             if (is_array($value)) {
                 foreach ($value as $multival) {
                     $xml .= $this->buildFieldXml($name, $multival);
                 }
             } else {
                 $xml .= $this->buildFieldXml($name, $value);
             }
         }
         $xml .= '</doc>';
     }
     $xml .= '</docs>';
     return $xml;
 }