/** * Check now if we have an index. * * @param mixed $body Setter mode. * @return array Getter mode : the body. * @throws Simples_Request_Exception */ public function body($body = null) { if (!isset($body) && !isset($this->_options['index'])) { throw new Simples_Request_Exception('Empty key "index" : you should specify the index name !'); } return parent::body($body); }
/** * Overrides body for bulk indexing. * * @param mixed $body Data to index. * @return mixed Data to index. */ public function body($body = null) { if (is_array($body) && is_numeric(key($body))) { $this->_multiple = true; $this->_body = $body; return $this; } elseif (isset($body)) { return parent::body($body); } if ($this->multiple()) { $return = array('docs' => array()); foreach ($this->_body as $id) { $return['docs'][] = array('_index' => $this->_options['index'], '_type' => $this->_options['type'], '_id' => $id); } return $return; } return parent::body(); }
/** * Body without null values. * * @param array $body * @return type */ public function body($body = null) { if (isset($body)) { return parent::body($body); } $body = parent::body(); if (empty($body['query'])) { // Force a match_all $body['query'] = $this->_query->to('array'); } if (empty($body['filter']) && $this->_filters->count()) { $body['filter'] = $this->_filters->to('array'); } if (empty($body['facets']) && $this->_facets->count()) { $body['facets'] = $this->_facets->to('array'); } // Sort format if (!empty($body['sort'])) { $body['sort'] = $this->_prepareSort($body['sort']); } // Highlights format if (!empty($body['highlight']['fields'])) { $highlight = array(); foreach ($body['highlight']['fields'] as $key => $value) { if (is_numeric($key)) { $highlight[$value] = new stdClass(); } else { $highlight[$key] = $value; } } $body['highlight']['fields'] = $highlight; } foreach ($body as $key => $value) { if (!isset($value)) { unset($body[$key]); } } return $body; }