|
1
|
|
|
<?php |
|
2
|
|
|
namespace Codappix\SearchCore\Domain\Model; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* Copyright (C) 2016 Daniel Siepmann <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software; you can redistribute it and/or |
|
8
|
|
|
* modify it under the terms of the GNU General Public License |
|
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
10
|
|
|
* of the License, or (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program; if not, write to the Free Software |
|
19
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20
|
|
|
* 02110-1301, USA. |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
use Codappix\SearchCore\Connection\ConnectionInterface; |
|
24
|
|
|
use Codappix\SearchCore\Connection\FacetRequestInterface; |
|
25
|
|
|
use Codappix\SearchCore\Connection\SearchRequestInterface; |
|
26
|
|
|
use Codappix\SearchCore\Domain\Search\SearchService; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Represents a search request used to process an actual search. |
|
30
|
|
|
*/ |
|
31
|
|
|
class SearchRequest implements SearchRequestInterface |
|
32
|
|
|
{ |
|
33
|
|
|
use QueryResultInterfaceStub; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The search string provided by the user, the actual term to search for. |
|
37
|
|
|
* |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $query = ''; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $filter = []; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $facets = []; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var int |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $offset = 0; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var int |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $limit = 10; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Used for QueryInterface implementation to allow execute method to work. |
|
64
|
|
|
* |
|
65
|
|
|
* @var ConnectionInterface |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $connection = null; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var SearchService |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $searchService = null; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
4 |
|
* @param string $query |
|
76
|
|
|
*/ |
|
77
|
4 |
|
public function __construct(string $query = '') |
|
78
|
4 |
|
{ |
|
79
|
|
|
$this->query = $query; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getQuery() : string |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->query; |
|
|
|
|
|
|
85
|
4 |
|
} |
|
86
|
|
|
|
|
87
|
4 |
|
public function getSearchTerm() : string |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->query; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
2 |
|
* @param array $filter |
|
94
|
|
|
*/ |
|
95
|
2 |
|
public function setFilter(array $filter) |
|
96
|
2 |
|
{ |
|
97
|
2 |
|
$filter = \TYPO3\CMS\Core\Utility\ArrayUtility::removeArrayEntryByValue($filter, ''); |
|
98
|
|
|
$this->filter = \TYPO3\CMS\Core\Utility\ArrayUtility::filterRecursive($filter, function ($value) { |
|
99
|
4 |
|
return (!is_array($value) && trim($value) !== '') |
|
100
|
|
|
|| is_array($value) && count($value) !== 0; |
|
101
|
4 |
|
}); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
4 |
|
public function hasFilter() : bool |
|
105
|
|
|
{ |
|
106
|
4 |
|
return count($this->filter) > 0; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getFilter() : array |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->filter; |
|
112
|
2 |
|
} |
|
113
|
|
|
|
|
114
|
2 |
|
/** |
|
115
|
2 |
|
* Add a facet to gather in this search request. |
|
116
|
|
|
*/ |
|
117
|
|
|
public function addFacet(FacetRequestInterface $facet) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->facets[$facet->getIdentifier()] = $facet; |
|
120
|
4 |
|
} |
|
121
|
|
|
|
|
122
|
4 |
|
/** |
|
123
|
|
|
* Returns all configured facets to fetch in this search request. |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getFacets() : array |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->facets; |
|
128
|
|
|
} |
|
129
|
4 |
|
|
|
130
|
|
|
/** |
|
131
|
4 |
|
* Define connection to use for this request. |
|
132
|
4 |
|
* Necessary to allow implementation of execute for interface. |
|
133
|
|
|
*/ |
|
134
|
4 |
|
public function setConnection(ConnectionInterface $connection) |
|
135
|
|
|
{ |
|
136
|
4 |
|
$this->connection = $connection; |
|
137
|
4 |
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function setSearchService(SearchService $searchService) |
|
140
|
|
|
{ |
|
141
|
|
|
$this->searchService = $searchService; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
// Extbase QueryInterface |
|
145
|
|
|
// Current implementation covers only paginate widget support. |
|
146
|
|
|
public function execute($returnRawQueryResult = false) |
|
|
|
|
|
|
147
|
|
|
{ |
|
148
|
|
|
if (! ($this->connection instanceof ConnectionInterface)) { |
|
|
|
|
|
|
149
|
|
|
throw new \InvalidArgumentException( |
|
150
|
|
|
'Connection was not set before, therefore execute can not work. Use `setConnection` before.', |
|
151
|
|
|
1502197732 |
|
152
|
|
|
); |
|
153
|
|
|
} |
|
154
|
|
|
if (! ($this->searchService instanceof SearchService)) { |
|
|
|
|
|
|
155
|
|
|
throw new \InvalidArgumentException( |
|
156
|
|
|
'SearchService was not set before, therefore execute can not work. Use `setSearchService` before.', |
|
157
|
|
|
1520325175 |
|
158
|
|
|
); |
|
159
|
4 |
|
} |
|
160
|
|
|
|
|
161
|
4 |
|
return $this->searchService->processResult($this->connection->search($this)); |
|
162
|
|
|
} |
|
163
|
4 |
|
|
|
164
|
|
|
public function setLimit($limit) |
|
165
|
|
|
{ |
|
166
|
|
|
$this->limit = (int) $limit; |
|
167
|
|
|
|
|
168
|
|
|
return $this; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
public function setOffset($offset) |
|
172
|
|
|
{ |
|
173
|
4 |
|
$this->offset = (int) $offset; |
|
174
|
|
|
|
|
175
|
4 |
|
return $this; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
4 |
|
public function getLimit(): int |
|
179
|
|
|
{ |
|
180
|
4 |
|
return $this->limit; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
public function getOffset(): int |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->offset; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function getSource() |
|
189
|
|
|
{ |
|
190
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196146); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function setOrderings(array $orderings) |
|
|
|
|
|
|
194
|
|
|
{ |
|
195
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196163); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function matching($constraint) |
|
|
|
|
|
|
199
|
|
|
{ |
|
200
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196197); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function logicalAnd($constraint1) |
|
|
|
|
|
|
204
|
|
|
{ |
|
205
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196166); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function logicalOr($constraint1) |
|
|
|
|
|
|
209
|
|
|
{ |
|
210
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196198); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
public function logicalNot(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint) |
|
|
|
|
|
|
214
|
|
|
{ |
|
215
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196166); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
public function equals($propertyName, $operand, $caseSensitive = true) |
|
|
|
|
|
|
219
|
|
|
{ |
|
220
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196199); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function contains($propertyName, $operand) |
|
|
|
|
|
|
224
|
|
|
{ |
|
225
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196200); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
public function in($propertyName, $operand) |
|
|
|
|
|
|
229
|
|
|
{ |
|
230
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196167); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
public function lessThan($propertyName, $operand) |
|
|
|
|
|
|
234
|
|
|
{ |
|
235
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196201); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
public function lessThanOrEqual($propertyName, $operand) |
|
|
|
|
|
|
239
|
|
|
{ |
|
240
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
public function greaterThan($propertyName, $operand) |
|
|
|
|
|
|
244
|
|
|
{ |
|
245
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196202); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
public function greaterThanOrEqual($propertyName, $operand) |
|
|
|
|
|
|
249
|
|
|
{ |
|
250
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
public function getType() |
|
254
|
|
|
{ |
|
255
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196203); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings) |
|
|
|
|
|
|
259
|
|
|
{ |
|
260
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196168); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
public function getQuerySettings() |
|
264
|
|
|
{ |
|
265
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196205); |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
public function count() |
|
269
|
|
|
{ |
|
270
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196169); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
public function getOrderings() |
|
274
|
|
|
{ |
|
275
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196206); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
public function getConstraint() |
|
279
|
|
|
{ |
|
280
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196171); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
public function isEmpty($propertyName) |
|
|
|
|
|
|
284
|
|
|
{ |
|
285
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196207); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source) |
|
|
|
|
|
|
289
|
|
|
{ |
|
290
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196172); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
public function getStatement() |
|
294
|
|
|
{ |
|
295
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
public function current() |
|
299
|
|
|
{ |
|
300
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
public function next() |
|
304
|
|
|
{ |
|
305
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
public function key() |
|
309
|
|
|
{ |
|
310
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
public function valid() |
|
314
|
|
|
{ |
|
315
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208); |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
public function rewind() |
|
319
|
|
|
{ |
|
320
|
|
|
throw new \BadMethodCallException('Method is not implemented yet.', 1502196208); |
|
321
|
|
|
} |
|
322
|
|
|
} |
|
323
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: