Passed
Push — master ( 4e40a2...cc3f84 )
by Timo
24:09
created

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