1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* YAWIK |
4
|
|
|
* |
5
|
|
|
* @filesource |
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
7
|
|
|
* @license MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Solr\Bridge; |
11
|
|
|
|
12
|
|
|
use Core\Entity\AbstractIdentifiableModificationDateAwareEntity as EntityType; |
13
|
|
|
use Jobs\Repository\Job as JobRepository; |
14
|
|
|
use Solr\Filter\AbstractPaginationQuery; |
15
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class ResultConverter |
19
|
|
|
* |
20
|
|
|
* Convert SOLR query result into Doctrine ODM Entity |
21
|
|
|
* |
22
|
|
|
* @author Anthonius Munthi <[email protected]> |
23
|
|
|
* @package Solr\Bridge |
24
|
|
|
* @since 0.26 |
25
|
|
|
*/ |
26
|
|
|
class ResultConverter |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Current filter used for conversion |
30
|
|
|
* |
31
|
|
|
* @var AbstractPaginationQuery |
32
|
|
|
*/ |
33
|
|
|
protected $filter; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* if set, the city name of the found location overwrites the general job location |
37
|
|
|
* |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
protected $useGeoLocation=false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var ServiceLocatorInterface |
44
|
|
|
*/ |
45
|
|
|
protected $sl; |
46
|
|
|
|
47
|
|
|
public function __construct(ServiceLocatorInterface $sl) |
48
|
|
|
{ |
49
|
|
|
$this->sl = $sl; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Convert result into entity |
54
|
|
|
* |
55
|
|
|
* @param AbstractPaginationQuery $filter |
56
|
|
|
* @param \SolrQueryResponse $queryResponse |
57
|
|
|
* @return EntityType[] |
58
|
|
|
*/ |
59
|
|
|
public function convert($filter, $queryResponse) |
60
|
|
|
{ |
61
|
|
|
$this->filter = $filter; |
62
|
|
|
$response = $queryResponse->getResponse(); |
|
|
|
|
63
|
|
|
$facets = $response['facet_counts']; |
64
|
|
|
$class = $filter->getProxyClass(); |
65
|
|
|
$entities = []; |
66
|
|
|
$solrObjects = []; |
67
|
|
|
|
68
|
|
|
foreach($response['response']['docs'] as $doc){ |
69
|
|
|
$solrObjects[$doc->id] = $doc; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/* @var JobRepository $repository */ |
73
|
|
|
$keys = array_keys($solrObjects); |
74
|
|
|
$repository = $this->sl->get('repositories')->get($filter->getRepositoryName()); |
75
|
|
|
$qb = $repository->createQueryBuilder(); |
76
|
|
|
$qb->hydrate(true)->field('id')->in($keys); |
77
|
|
|
$result = $qb->getQuery()->execute(); |
78
|
|
|
foreach($result as $document){ |
79
|
|
|
$solrObject = $solrObjects[$document->getId()]; |
80
|
|
|
$entity = new $class($document,$solrObject); |
81
|
|
|
$entity->setFacets($facets); |
82
|
|
|
$entities[] = $entity; |
83
|
|
|
} |
84
|
|
|
return $entities; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Create a new instance of ResultConverter |
89
|
|
|
* @param ServiceLocatorInterface $sl |
90
|
|
|
* @return ResultConverter |
91
|
|
|
*/ |
92
|
|
|
static public function factory(ServiceLocatorInterface $sl) |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
return new static($sl); |
95
|
|
|
} |
96
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.