|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DoctrineElastic\Elastic; |
|
4
|
|
|
|
|
5
|
|
|
use DoctrineElastic\ElasticEntityManager; |
|
6
|
|
|
use DoctrineElastic\Query\QueryParser; |
|
7
|
|
|
use DoctrineElastic\Query\ElasticQueryExecutor; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* DoctrineElastic Query representation |
|
11
|
|
|
* |
|
12
|
|
|
* @author Ands |
|
13
|
|
|
*/ |
|
14
|
|
|
class ElasticQuery { |
|
15
|
|
|
|
|
16
|
|
|
/** @var ElasticEntityManager */ |
|
17
|
|
|
protected $entityManager; |
|
18
|
|
|
|
|
19
|
|
|
/** @var ElasticQueryExecutor */ |
|
20
|
|
|
protected $queryExecutor; |
|
21
|
|
|
|
|
22
|
|
|
/** @var int */ |
|
23
|
|
|
protected $_firstResult; |
|
24
|
|
|
|
|
25
|
|
|
/** @var int */ |
|
26
|
|
|
protected $_maxResults; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
protected $_dql; |
|
30
|
|
|
|
|
31
|
|
|
/** @var array */ |
|
32
|
|
|
protected $_parameters; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct(ElasticEntityManager $entityManager) { |
|
35
|
|
|
$this->entityManager = $entityManager; |
|
36
|
|
|
$this->queryExecutor = new ElasticQueryExecutor($entityManager); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getResult() { |
|
40
|
|
|
$parser = new QueryParser($this); |
|
41
|
|
|
$searchParams = $parser->parseElasticQuery(); |
|
42
|
|
|
|
|
43
|
|
|
return $this->queryExecutor->execute($searchParams, $parser->getRootClass()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getDQL() { |
|
47
|
|
|
return $this->_dql; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function setDQL($dql) { |
|
51
|
|
|
$this->_dql = $dql; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected function processParameterMappings($paramMappings) { |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return mixed |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getParameters() { |
|
62
|
|
|
return $this->_parameters; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param mixed $parameters |
|
67
|
|
|
* @return ElasticQuery |
|
68
|
|
|
*/ |
|
69
|
|
|
public function setParameters($parameters) { |
|
70
|
|
|
$this->_parameters = $parameters; |
|
|
|
|
|
|
71
|
|
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function setFirstResult($offset) { |
|
75
|
|
|
$this->_firstResult = $offset; |
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function setMaxResults($limit) { |
|
80
|
|
|
$this->_maxResults = $limit; |
|
81
|
|
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getFirstResult() { |
|
85
|
|
|
return $this->_firstResult; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getMaxResults() { |
|
89
|
|
|
return $this->_maxResults; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function getEntityManager() { |
|
93
|
|
|
return $this->entityManager; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function getOneOrNullResult() { |
|
97
|
|
|
$results = $this->getResult(); |
|
98
|
|
|
|
|
99
|
|
|
return count($results) ? reset($results) : null; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function getSingleResult() { |
|
103
|
|
|
return $this->getOneOrNullResult(); |
|
104
|
|
|
} |
|
105
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.