Passed
Pull Request — release-11.5.x (#3256)
by Rafael
47:51 queued 16:46
created

SearchResultSet::addSearchResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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