Example #1
0
 /**
  * Smart data recovering : with _source and without.
  *
  * Options :
  * - clean (bool) : remove the empty values and convert numerics to floats
  * - source (mixed) : false to force not working with "_source", true to force working with it. Else, "auto".
  *
  * @return array	Prepared data.
  */
 protected function _data(array $options = array())
 {
     $options += array('clean' => false, 'source' => 'auto', 'cast' => $this->_config['cast']);
     $data = parent::_data($options);
     if ($options['clean']) {
         $this->_clean($data, $options);
     }
     $source = (bool) $options['source'];
     if ($options['source'] === 'auto' && !isset($this->_properties)) {
         $source = false;
     }
     if (!$source) {
         return $this->_export($data, $options);
     } else {
         $return = array();
         // Rename properties
         if (isset($this->_properties)) {
             $properties = $this->_properties->to('array');
             foreach ($properties as $key => $value) {
                 $return['_' . $key] = $value;
             }
         }
         // Add the source
         $return['_source'] = $this->_export($data, $options);
     }
     return $return;
 }
Example #2
0
 /**
  * Returns the doc in json (here to be override in Simples_Request_Uopdate)
  *
  * @param  Simples_Document $document Doc to index
  * @return string                     Json string
  */
 protected function _jsonDoc(Simples_Document $document, array $options = array())
 {
     return $document->to('json', $options + $this->_options);
 }
Example #3
0
 /**
  * Returns the doc in json inside a "doc" instruction.
  *
  * @param  Simples_Document $document Doc to index
  * @return string                     Json string
  */
 protected function _jsonDoc(Simples_Document $document, array $options = array())
 {
     $return = array('doc' => $document->to('array', $options + $this->_options));
     return json_encode($return);
 }
Example #4
0
 public function testCleanFloatInf()
 {
     // Test clean
     $document = new Simples_Document(array('string' => '3E7210'));
     $res = $document->to('array', array('clean' => true));
     $this->assertTrue($res['string'] === '3E7210');
     $res = $document->to('json', array('clean' => true));
     $this->assertEquals($res, '{"string":"3E7210"}');
 }