1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoctrineElastic\Elastic; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Entity class for representation of Elasticsearch api search query |
7
|
|
|
* |
8
|
|
|
* @author Andsalves <[email protected]> |
9
|
|
|
* @author Allan BRUYERE <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class SearchParams |
12
|
|
|
{ |
13
|
|
|
/* extrapolating elastic max results, ignoring elastic default as 10 */ |
14
|
|
|
const DEFAULT_LIMIT_RESULTS = 1000000000; |
15
|
|
|
|
16
|
|
|
protected $index; |
17
|
|
|
|
18
|
|
|
protected $type; |
19
|
|
|
|
20
|
|
|
protected $parent; |
21
|
|
|
|
22
|
|
|
protected $body = []; |
23
|
|
|
|
24
|
|
|
protected $from = 0; |
25
|
|
|
|
26
|
|
|
protected $size = self::DEFAULT_LIMIT_RESULTS; |
27
|
|
|
|
28
|
|
|
protected $sort = []; |
29
|
|
|
|
30
|
|
|
protected $aggregate = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function getIndex() |
36
|
|
|
{ |
37
|
|
|
return $this->index; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $index |
42
|
|
|
* @return SearchParams |
43
|
|
|
*/ |
44
|
|
|
public function setIndex($index) |
45
|
|
|
{ |
46
|
|
|
$this->index = $index; |
47
|
|
|
|
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getType() |
55
|
|
|
{ |
56
|
|
|
return $this->type; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $type |
61
|
|
|
* @return SearchParams |
62
|
|
|
*/ |
63
|
|
|
public function setType($type) |
64
|
|
|
{ |
65
|
|
|
$this->type = $type; |
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
public function getBody() |
73
|
|
|
{ |
74
|
|
|
return $this->body; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param array $body |
79
|
|
|
* @return SearchParams |
80
|
|
|
*/ |
81
|
|
|
public function setBody(array $body = []) |
82
|
|
|
{ |
83
|
|
|
$this->body = $body; |
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return int |
90
|
|
|
*/ |
91
|
|
|
public function getSize() |
92
|
|
|
{ |
93
|
|
|
return $this->size; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param int $size |
98
|
|
|
* @return SearchParams |
99
|
|
|
*/ |
100
|
|
|
public function setSize($size) |
101
|
|
|
{ |
102
|
|
|
$this->size = $size; |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return array |
109
|
|
|
*/ |
110
|
|
|
public function getSort() |
111
|
|
|
{ |
112
|
|
|
return $this->sort; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param array $sort |
117
|
|
|
* @return SearchParams |
118
|
|
|
*/ |
119
|
|
|
public function setSort(array $sort = []) |
120
|
|
|
{ |
121
|
|
|
$this->sort = $sort; |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return int |
128
|
|
|
*/ |
129
|
|
|
public function getFrom() |
130
|
|
|
{ |
131
|
|
|
return $this->from; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param int $from |
136
|
|
|
* @return SearchParams |
137
|
|
|
*/ |
138
|
|
|
public function setFrom($from) |
139
|
|
|
{ |
140
|
|
|
$this->from = $from; |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return mixed |
147
|
|
|
*/ |
148
|
|
|
public function getParent() |
149
|
|
|
{ |
150
|
|
|
return $this->parent; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param mixed $parent |
155
|
|
|
* @return SearchParams |
156
|
|
|
*/ |
157
|
|
|
public function setParent($parent) |
158
|
|
|
{ |
159
|
|
|
$this->parent = $parent; |
160
|
|
|
|
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return array |
166
|
|
|
*/ |
167
|
|
|
public function getAggregate() |
168
|
|
|
{ |
169
|
|
|
return $this->aggregate; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param array $aggregate |
174
|
|
|
* @return SearchParams |
175
|
|
|
*/ |
176
|
|
|
public function setAggregate($aggregate) |
177
|
|
|
{ |
178
|
|
|
$this->aggregate = $aggregate; |
179
|
|
|
|
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return bool |
185
|
|
|
*/ |
186
|
|
|
public function isValid() |
187
|
|
|
{ |
188
|
|
|
return boolval($this->index); |
189
|
|
|
} |
190
|
|
|
} |