From ccc920d46b701158470319a53338633729f3ea5a Mon Sep 17 00:00:00 2001 From: nurikabe Date: Wed, 18 Apr 2012 14:39:32 -0300 Subject: [PATCH 1/2] Throw a more meaningful error when the number of items retrieved by Doctrine is less than the number of items from ElasticSearch. --- Doctrine/AbstractElasticaToModelTransformer.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doctrine/AbstractElasticaToModelTransformer.php b/Doctrine/AbstractElasticaToModelTransformer.php index 7bb1b71..ae84cab 100644 --- a/Doctrine/AbstractElasticaToModelTransformer.php +++ b/Doctrine/AbstractElasticaToModelTransformer.php @@ -5,6 +5,7 @@ namespace FOQ\ElasticaBundle\Doctrine; use FOQ\ElasticaBundle\HybridResult; use FOQ\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface; use Elastica_Document; +use RuntimeException; /** * Maps Elastica documents with Doctrine objects @@ -89,6 +90,9 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran public function hybridTransform(array $elasticaObjects) { $objects = $this->transform($elasticaObjects); + if (count($objects) < count($elasticaObjects)) { + throw new RuntimeException('Cannot transform all Elastica results into objects.'); + }; $result = array(); for ($i = 0; $i < count($elasticaObjects); $i++) { From 4b30686359ca8d145d5fe20dc43574efe19c1f0d Mon Sep 17 00:00:00 2001 From: nurikabe Date: Thu, 19 Apr 2012 15:05:18 +0100 Subject: [PATCH 2/2] Somewhat clearer exception when Elastica results do not match Doctrine objects. Consistent behavior for both transform() and hybrdidTrasnform(). --- Doctrine/AbstractElasticaToModelTransformer.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Doctrine/AbstractElasticaToModelTransformer.php b/Doctrine/AbstractElasticaToModelTransformer.php index ae84cab..81d5cca 100644 --- a/Doctrine/AbstractElasticaToModelTransformer.php +++ b/Doctrine/AbstractElasticaToModelTransformer.php @@ -5,7 +5,6 @@ namespace FOQ\ElasticaBundle\Doctrine; use FOQ\ElasticaBundle\HybridResult; use FOQ\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface; use Elastica_Document; -use RuntimeException; /** * Maps Elastica documents with Doctrine objects @@ -74,6 +73,9 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran }, $elasticaObjects); $objects = $this->findByIdentifiers($this->objectClass, $this->options['identifier'], $ids, $this->options['hydrate']); + if (count($objects) < count($elasticaObjects)) { + throw new \RuntimeException('Cannot find corresponding Doctrine objects for all Elastica results.'); + }; $identifierGetter = 'get'.ucfirst($this->options['identifier']); @@ -90,9 +92,6 @@ abstract class AbstractElasticaToModelTransformer implements ElasticaToModelTran public function hybridTransform(array $elasticaObjects) { $objects = $this->transform($elasticaObjects); - if (count($objects) < count($elasticaObjects)) { - throw new RuntimeException('Cannot transform all Elastica results into objects.'); - }; $result = array(); for ($i = 0; $i < count($elasticaObjects); $i++) {