/** * {@inheritdoc} */ public function toArray() { try { return JSON::parse($input = $this->__toString()); } catch (JSONParseException $e) { throw new InvalidException(sprintf('The produced query is not a valid json string : "%s"', $input)); } }
/** * {@inheritdoc} */ public function toArray() { try { return JSON::parse($this->__toString()); } catch (JSONParseException $e) { throw new InvalidException('The query produced is invalid'); } }
/** * @group functional */ public function testPartialFailure() { $this->_checkScriptInlineSetting(); $client = $this->_getClient(); $index = $client->getIndex('elastica_partial_failure'); $index->create(array('index' => array('number_of_shards' => 5, 'number_of_replicas' => 0)), true); $type = $index->getType('folks'); $type->addDocument(new Document('', array('name' => 'ruflin'))); $type->addDocument(new Document('', array('name' => 'bobrik'))); $type->addDocument(new Document('', array('name' => 'kimchy'))); $index->refresh(); $query = Query::create(array('query' => array('filtered' => array('filter' => array('script' => array('script' => 'doc["undefined"] > 8')))))); try { $index->search($query); $this->fail('PartialShardFailureException should have been thrown'); } catch (PartialShardFailureException $e) { $resultSet = new ResultSet($e->getResponse(), $query); $this->assertEquals(0, count($resultSet->getResults())); $message = JSON::parse($e->getMessage()); $this->assertTrue(isset($message['failures']), 'Failures are absent'); $this->assertGreaterThan(0, count($message['failures']), 'Failures are empty'); } }
/** * Response data array. * * @return array Response data array */ public function getData() { if ($this->_response == null) { $response = $this->_responseString; if ($response === false) { $this->_error = true; } else { try { if ($this->getJsonBigintConversion()) { $response = JSON::parse($response, true, 512, JSON_BIGINT_AS_STRING); } else { $response = JSON::parse($response); } } catch (JSONParseException $e) { // leave response as is if parse fails } } if (empty($response)) { $response = []; } if (is_string($response)) { $response = ['message' => $response]; } $this->_response = $response; } return $this->_response; }
/** * Response data array. * * @return array Response data array */ public function getData() { if ($this->_response == null) { $response = $this->_responseString; if ($response === false) { $this->_error = true; } else { try { $response = JSON::parse($response); } catch (JSONParseException $e) { // leave reponse as is if parse fails } } if (empty($response)) { $response = array(); } if (is_string($response)) { $response = array('message' => $response); } $this->_response = $response; } return $this->_response; }