public function testNotMerged() { $query = new Simples_Request_Search_Builder_Query(); $query->must()->match('scharrier')->in(array('username', 'retweet'))->field('category_id')->match(array('1', '2', '3'))->not()->field('type')->match('administreur'); $res = $query->to('array'); $this->assertEquals(2, count($res['bool']['must'])); $this->assertEquals(1, count($res['bool']['must_not'])); }
/** * 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; }