1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet; |
4
|
|
|
|
5
|
|
|
/*************************************************************** |
6
|
|
|
* Copyright notice |
7
|
|
|
* |
8
|
|
|
* (c) 2015-2016 Timo Schmidt <[email protected]> |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\Query\Query; |
29
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\AbstractFacet; |
30
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\FacetCollection; |
31
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result\SearchResultCollection; |
32
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Sorting\Sorting; |
33
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Sorting\SortingCollection; |
34
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Spellchecking\Suggestion; |
35
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequest; |
36
|
|
|
use ApacheSolrForTypo3\Solr\Search; |
37
|
|
|
|
38
|
|
|
//@deprecated |
39
|
|
|
//@todo this alias can be removed when the old class was dropped |
40
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result\SearchResult as NewSearchResult; |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The SearchResultSet is used to provided access to the \Apache_Solr_Response and |
45
|
|
|
* other relevant information, like the used Query and Request objects. |
46
|
|
|
* |
47
|
|
|
* @author Timo Schmidt <[email protected]> |
48
|
|
|
*/ |
49
|
|
|
class SearchResultSet |
50
|
|
|
{ |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var Query |
54
|
|
|
*/ |
55
|
|
|
protected $usedQuery = null; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var SearchRequest |
59
|
|
|
*/ |
60
|
|
|
protected $usedSearchRequest = null; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var Search |
64
|
|
|
*/ |
65
|
|
|
protected $usedSearch; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var \Apache_Solr_Response |
69
|
|
|
*/ |
70
|
|
|
protected $response = null; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var int |
74
|
|
|
*/ |
75
|
|
|
protected $usedPage = 0; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var int |
79
|
|
|
*/ |
80
|
|
|
protected $usedResultsPerPage = 0; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var array |
84
|
|
|
*/ |
85
|
|
|
protected $usedAdditionalFilters = []; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @var SearchResultCollection |
89
|
|
|
*/ |
90
|
|
|
protected $searchResults = null; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @var int |
94
|
|
|
*/ |
95
|
|
|
protected $allResultCount = 0; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var Suggestion[] |
99
|
|
|
*/ |
100
|
|
|
protected $spellCheckingSuggestions = []; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @var FacetCollection |
104
|
|
|
*/ |
105
|
|
|
protected $facets = null; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @var SortingCollection |
109
|
|
|
*/ |
110
|
|
|
protected $sortings = null; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var bool |
114
|
|
|
*/ |
115
|
|
|
protected $isAutoCorrected = false; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @var string |
119
|
|
|
*/ |
120
|
|
|
protected $initialQueryString = ''; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @var string |
124
|
|
|
*/ |
125
|
|
|
protected $correctedQueryString = ''; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @var bool |
129
|
|
|
*/ |
130
|
|
|
protected $hasSearched = false; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return \ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet |
134
|
|
|
*/ |
135
|
96 |
|
public function __construct() |
136
|
|
|
{ |
137
|
96 |
|
$this->facets = new FacetCollection(); |
138
|
96 |
|
$this->sortings = new SortingCollection(); |
139
|
96 |
|
$this->searchResults = new SearchResultCollection(); |
140
|
96 |
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param int $allResultCount |
144
|
|
|
*/ |
145
|
68 |
|
public function setAllResultCount($allResultCount) |
146
|
|
|
{ |
147
|
68 |
|
$this->allResultCount = $allResultCount; |
148
|
68 |
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return int |
152
|
|
|
*/ |
153
|
33 |
|
public function getAllResultCount() |
154
|
|
|
{ |
155
|
33 |
|
return $this->allResultCount; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param Suggestion $suggestion |
160
|
|
|
*/ |
161
|
5 |
|
public function addSpellCheckingSuggestion(Suggestion $suggestion) |
162
|
|
|
{ |
163
|
5 |
|
$this->spellCheckingSuggestions[$suggestion->getSuggestion()] = $suggestion; |
164
|
5 |
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return bool |
168
|
|
|
*/ |
169
|
34 |
|
public function getHasSpellCheckingSuggestions() |
170
|
|
|
{ |
171
|
34 |
|
return count($this->spellCheckingSuggestions) > 0; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param \ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Spellchecking\Suggestion[] $spellCheckingSuggestions |
176
|
|
|
*/ |
177
|
|
|
public function setSpellCheckingSuggestions($spellCheckingSuggestions) |
178
|
|
|
{ |
179
|
|
|
$this->spellCheckingSuggestions = $spellCheckingSuggestions; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return \ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Spellchecking\Suggestion[] |
184
|
|
|
*/ |
185
|
4 |
|
public function getSpellCheckingSuggestions() |
186
|
|
|
{ |
187
|
4 |
|
return $this->spellCheckingSuggestions; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return FacetCollection |
192
|
|
|
*/ |
193
|
68 |
|
public function getFacets() |
194
|
|
|
{ |
195
|
68 |
|
return $this->facets; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param AbstractFacet $facet |
200
|
|
|
*/ |
201
|
62 |
|
public function addFacet(AbstractFacet $facet) |
202
|
|
|
{ |
203
|
62 |
|
$this->facets->addFacet($facet); |
204
|
62 |
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param Sorting $sorting |
208
|
|
|
*/ |
209
|
33 |
|
public function addSorting(Sorting $sorting) |
210
|
|
|
{ |
211
|
33 |
|
$this->sortings->addSorting($sorting); |
212
|
33 |
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return SortingCollection |
216
|
|
|
*/ |
217
|
32 |
|
public function getSortings() |
218
|
|
|
{ |
219
|
32 |
|
return $this->sortings; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @param \Apache_Solr_Response $response |
224
|
|
|
*/ |
225
|
84 |
|
public function setResponse($response) |
226
|
|
|
{ |
227
|
84 |
|
$this->response = $response; |
228
|
84 |
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return \Apache_Solr_Response |
232
|
|
|
*/ |
233
|
84 |
|
public function getResponse() |
234
|
|
|
{ |
235
|
84 |
|
return $this->response; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param array $usedAdditionalFilters |
240
|
|
|
*/ |
241
|
42 |
|
public function setUsedAdditionalFilters($usedAdditionalFilters) |
242
|
|
|
{ |
243
|
42 |
|
$this->usedAdditionalFilters = $usedAdditionalFilters; |
244
|
42 |
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @return array |
248
|
|
|
*/ |
249
|
|
|
public function getUsedAdditionalFilters() |
250
|
|
|
{ |
251
|
|
|
return $this->usedAdditionalFilters; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @param \ApacheSolrForTypo3\Solr\Domain\Search\Query\Query $usedQuery |
256
|
|
|
*/ |
257
|
43 |
|
public function setUsedQuery($usedQuery) |
258
|
|
|
{ |
259
|
43 |
|
$this->usedQuery = $usedQuery; |
260
|
43 |
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Retrieves the query object that has been used to build this result set. |
264
|
|
|
* |
265
|
|
|
* @return \ApacheSolrForTypo3\Solr\Domain\Search\Query\Query |
266
|
|
|
*/ |
267
|
35 |
|
public function getUsedQuery() |
268
|
|
|
{ |
269
|
35 |
|
return $this->usedQuery; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @param int $page |
274
|
|
|
*/ |
275
|
47 |
|
public function setUsedPage($page) |
276
|
|
|
{ |
277
|
47 |
|
$this->usedPage = $page; |
278
|
47 |
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Retrieve the page argument that has been used to build this SearchResultSet. |
282
|
|
|
* |
283
|
|
|
* @return int |
284
|
|
|
*/ |
285
|
31 |
|
public function getUsedPage() |
286
|
|
|
{ |
287
|
31 |
|
return $this->usedPage; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @return int |
292
|
|
|
*/ |
293
|
|
|
public function getResultsPerPage() |
294
|
|
|
{ |
295
|
|
|
return $this->usedQuery->getPagination()->getResultsPerPage(); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @param \ApacheSolrForTypo3\Solr\Domain\Search\SearchRequest $usedSearchRequest |
300
|
|
|
*/ |
301
|
90 |
|
public function setUsedSearchRequest($usedSearchRequest) |
302
|
|
|
{ |
303
|
90 |
|
$this->usedSearchRequest = $usedSearchRequest; |
304
|
90 |
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Retrieves the SearchRequest that has been used to build this SearchResultSet. |
308
|
|
|
* |
309
|
|
|
* @return \ApacheSolrForTypo3\Solr\Domain\Search\SearchRequest |
310
|
|
|
*/ |
311
|
87 |
|
public function getUsedSearchRequest() |
312
|
|
|
{ |
313
|
87 |
|
return $this->usedSearchRequest; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* @param \ApacheSolrForTypo3\Solr\Search $usedSearch |
318
|
|
|
*/ |
319
|
47 |
|
public function setUsedSearch($usedSearch) |
320
|
|
|
{ |
321
|
47 |
|
$this->usedSearch = $usedSearch; |
322
|
47 |
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* @return \ApacheSolrForTypo3\Solr\Search |
326
|
|
|
*/ |
327
|
33 |
|
public function getUsedSearch() |
328
|
|
|
{ |
329
|
33 |
|
return $this->usedSearch; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @param int $usedResultsPerPage |
334
|
|
|
*/ |
335
|
47 |
|
public function setUsedResultsPerPage($usedResultsPerPage) |
336
|
|
|
{ |
337
|
47 |
|
$this->usedResultsPerPage = $usedResultsPerPage; |
338
|
47 |
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @return int |
342
|
|
|
*/ |
343
|
26 |
|
public function getUsedResultsPerPage() |
344
|
|
|
{ |
345
|
26 |
|
return $this->usedResultsPerPage; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* @return SearchResultCollection |
350
|
|
|
*/ |
351
|
37 |
|
public function getSearchResults() |
352
|
|
|
{ |
353
|
37 |
|
return $this->searchResults; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @param SearchResultCollection $searchResults |
358
|
|
|
*/ |
359
|
42 |
|
public function setSearchResults($searchResults) |
360
|
|
|
{ |
361
|
42 |
|
$this->searchResults = $searchResults; |
362
|
42 |
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @param SearchResult $searchResult |
366
|
|
|
*/ |
367
|
|
|
public function addSearchResult(NewSearchResult $searchResult) |
368
|
|
|
{ |
369
|
|
|
$this->searchResults[] = $searchResult; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* @return boolean |
374
|
|
|
*/ |
375
|
30 |
|
public function getIsAutoCorrected() |
376
|
|
|
{ |
377
|
30 |
|
return $this->isAutoCorrected; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* @param boolean $wasAutoCorrected |
382
|
|
|
*/ |
383
|
1 |
|
public function setIsAutoCorrected($wasAutoCorrected) |
384
|
|
|
{ |
385
|
1 |
|
$this->isAutoCorrected = $wasAutoCorrected; |
386
|
1 |
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* @return string |
390
|
|
|
*/ |
391
|
1 |
|
public function getInitialQueryString() |
392
|
|
|
{ |
393
|
1 |
|
return $this->initialQueryString; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* @param string $initialQueryString |
398
|
|
|
*/ |
399
|
1 |
|
public function setInitialQueryString($initialQueryString) |
400
|
|
|
{ |
401
|
1 |
|
$this->initialQueryString = $initialQueryString; |
402
|
1 |
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* @return string |
406
|
|
|
*/ |
407
|
1 |
|
public function getCorrectedQueryString() |
408
|
|
|
{ |
409
|
1 |
|
return $this->correctedQueryString; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* @param string $correctedQueryString |
414
|
|
|
*/ |
415
|
1 |
|
public function setCorrectedQueryString($correctedQueryString) |
416
|
|
|
{ |
417
|
1 |
|
$this->correctedQueryString = $correctedQueryString; |
418
|
1 |
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* @return boolean |
422
|
|
|
*/ |
423
|
2 |
|
public function getHasSearched(): bool |
424
|
|
|
{ |
425
|
2 |
|
return $this->hasSearched; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* @param boolean $hasSearched |
430
|
|
|
*/ |
431
|
46 |
|
public function setHasSearched(bool $hasSearched) |
432
|
|
|
{ |
433
|
46 |
|
$this->hasSearched = $hasSearched; |
434
|
46 |
|
} |
435
|
|
|
} |
436
|
|
|
|