Browse files

Hybrid finder results

  • Loading branch information...
1 parent 5e19a37 commit 76f447ba7dc956cc9ea9b779d6e8b3df1cf28c93 @merk merk committed Feb 24, 2012
View
13 Doctrine/AbstractElasticaToModelTransformer.php
@@ -2,6 +2,7 @@
namespace FOQ\ElasticaBundle\Doctrine;
+use FOQ\ElasticaBundle\HybridResult;
use FOQ\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
use Elastica_Document;
@@ -85,6 +86,18 @@ public function transform(array $elasticaObjects)
return $objects;
}
+ public function hybridTransform(array $elasticaObjects)
+ {
+ $objects = $this->transform($elasticaObjects);
+
+ $result = array();
+ for ($i = 0; $i < count($elasticaObjects); $i++) {
+ $result[] = new HybridResult($elasticaObjects[$i], $objects[$i]);
+ }
+
+ return $result;
+ }
+
/**
* Fetches objects by theses identifier values
*
View
17 Finder/TransformedFinder.php
@@ -33,15 +33,30 @@ public function __construct(Elastica_Searchable $searchable, ElasticaToModelTran
**/
public function find($query, $limit = null)
{
+ $results = $this->search($query, $limit);
+
+ return $this->transformer->transform($results);
+ }
+
+ public function findHybrid($query, $limit = null)
+ {
+ $results = $this->search($query, $limit);
+
+ return $this->transformer->hybridTransform($results);
+ }
+
+ protected function search($query, $limit = null)
+ {
$queryObject = Elastica_Query::create($query);
if (null !== $limit) {
$queryObject->setLimit($limit);
}
$results = $this->searchable->search($queryObject)->getResults();
- return $this->transformer->transform($results);
+ return $results;
}
+
/**
* Gets a paginator wrapping the result of a search
*
View
27 HybridResult.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace FOQ\ElasticaBundle;
+
+use Elastica_Result;
+
+class HybridResult
+{
+ protected $result;
+ protected $transformed;
+
+ public function __construct(Elastica_Result $result, $transformed = null)
+ {
+ $this->result = $result;
+ $this->transformed = $transformed;
+ }
+
+ public function getTransformed()
+ {
+ return $this->transformed;
+ }
+
+ public function getResult()
+ {
+ return $this->result;
+ }
+}
View
14 Transformer/ElasticaToModelTransformerCollection.php
@@ -2,6 +2,8 @@
namespace FOQ\ElasticaBundle\Transformer;
+use FOQ\ElasticaBundle\HybridResult;
+
/**
* Holds a collection of transformers for an index wide transformation.
*
@@ -56,6 +58,18 @@ public function transform(array $elasticaObjects)
return $transformed;
}
+ public function hybridTransform(array $elasticaObjects)
+ {
+ $objects = $this->transform($elasticaObjects);
+
+ $result = array();
+ for ($i = 0; $i < count($elasticaObjects); $i++) {
+ $result[] = new HybridResult($elasticaObjects[$i], $objects[$i]);
+ }
+
+ return $result;
+ }
+
protected function getTypeToClassMap()
{
return array_map(function ($transformer) {
View
2 Transformer/ElasticaToModelTransformerInterface.php
@@ -16,6 +16,8 @@
**/
function transform(array $elasticaObjects);
+ function hybridTransform(array $elasticaObjects);
+
/**
* Returns the object class used by the transformer.
*

0 comments on commit 76f447b

Please sign in to comment.