Merge branch '2.0' of github.com:Exercise/FOQElasticaBundle into 2.0

This commit is contained in:
Richard Miller 2012-01-05 23:02:33 +00:00
commit 520a35bfc6
2 changed files with 34 additions and 8 deletions

View file

@ -20,14 +20,7 @@ class Client extends Elastica_Client
public function request($path, $method, $data = array())
{
$start = microtime(true);
//this is ghetto, but i couldnt figure out another way of making our site continue to behave normally even if ES was not running.
//Any improvements on this welcome. Perhaps another parameter that allows you to control if you want to ignore exceptions about ES not running
try {
$response = parent::request($path, $method, $data);
} catch(\Exception $e) {
//again, ghetto, but couldnt figure out how to return a default empty Elastica_Response
return new \Elastica_Response('{"took":0,"timed_out":false,"hits":{"total":0,"max_score":0,"hits":[]}}');
}
$response = parent::request($path, $method, $data);
if (null !== $this->logger) {
$time = microtime(true) - $start;

View file

@ -319,3 +319,36 @@ Any setting can be specified when declaring a type. For example, to enable a cus
blog:
mappings:
title: { boost: 8, analyzer: my_analyzer }
### Overriding the Client class to suppress exceptions
By default, exceptions from the Elastica client library will propogate through
the bundle's Client class. For instance, if the elasticsearch server is offline,
issuing a request will result in an `Elastica_Exception_Client` being thrown.
Depending on your needs, it may be desirable to suppress these exceptions and
allow searches to fail silently.
One way to achieve this is to override the `foq_elastica.client.class` service
container parameter with a custom class. In the following example, we override
the `Client::request()` method and return the equivalent of an empty search
response if an exception occurred.
```
<?php
namespace Acme\ElasticaBundle;
use FOQ\ElasticaBundle\Client as BaseClient;
class Client extends BaseClient
{
public function request($path, $method, $data = array())
{
try {
return parent::request($path, $method, $data);
} catch (\Elastica_Exception_Abstract $e) {
return new \Elastica_Response('{"took":0,"timed_out":false,"hits":{"total":0,"max_score":0,"hits":[]}}');
}
}
}
```