Passed
Push — master ( 5a6aec...5e9b73 )
by Gordon
05:22 queued 02:54
created

SearchResults   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 167
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 22
eloc 36
c 2
b 0
f 0
dl 0
loc 167
rs 10

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTotaNumberOfResults() 0 3 1
A setRecords() 0 3 1
A setPageSize() 0 3 1
A getTime() 0 3 1
A setTime() 0 3 1
A getTotalPages() 0 5 1
A setPage() 0 3 1
A getPageSize() 0 3 1
A setTotalNumberOfResults() 0 3 1
A setQuery() 0 3 1
A getSimilarTo() 0 3 1
A setSuggestions() 0 3 1
A setIndex() 0 3 1
A getSuggestions() 0 3 1
A getQuery() 0 3 1
A getRecords() 0 5 2
A setSimilarTo() 0 3 1
A getPage() 0 3 1
A addFacet() 0 3 1
A getFacets() 0 3 1
1
<?php declare(strict_types = 1);
2
3
/**
4
 * Created by PhpStorm.
5
 * User: gordon
6
 * Date: 24/3/2561
7
 * Time: 20:36 น.
8
 */
9
10
namespace Suilven\FreeTextSearch\Container;
11
12
use SilverStripe\ORM\ArrayList;
13
14
/**
15
 * Class SearchResults
16
 *
17
 * Store the search results in a manner that is renderable in a SilverStripe template
18
 *
19
 * @package Suilven\FreeTextSearch\Container
20
 */
21
class SearchResults
22
{
23
24
    /** @var array<\Suilven\FreeTextSearch\Container\Facet> */
25
    private $facets;
26
27
    /** @var string */
28
    private $index;
29
30
    /** @var int the total number of results */
31
    private $totalNumberOfResults = 0;
32
33
    /** @var int */
34
    private $page = 0;
35
36
    /** @var int */
37
    private $pageSize = 20;
38
39
    /** @var string */
40
    private $query = '';
41
42
    /** @var \SilverStripe\ORM\ArrayList|null */
43
    private $records;
44
45
    /** @var array<string> */
46
    private $suggestions;
47
48
    /** @var float the time in seconds */
49
    private $time;
50
51
    /** @var \SilverStripe\ORM\DataObject|null */
52
    private $searchSimilarTo = null;
53
54
    public function __construct()
55
    {
56
        $this->time = 0;
57
        $this->suggestions =[];
58
    }
59
60
61
    public function addFacet(Facet $facet): void
62
    {
63
        $this->facets[] = $facet;
64
    }
65
66
67
    public function setIndex(string $newIndex): void
68
    {
69
        $this->index = $newIndex;
70
    }
71
72
73
    public function getTotaNumberOfResults(): int
74
    {
75
        return $this->totalNumberOfResults;
76
    }
77
78
79
    public function setTotalNumberOfResults(int $newTotalNumberOfResults): void
80
    {
81
        $this->totalNumberOfResults = $newTotalNumberOfResults;
82
    }
83
84
85
    public function getTotalPages(): int
86
    {
87
        $nPages = \ceil($this->totalNumberOfResults / $this->pageSize);
88
89
        return \intval($nPages);
90
    }
91
92
93
    public function getPage(): int
94
    {
95
        return $this->page;
96
    }
97
98
99
    public function setPage(int $newPage): void
100
    {
101
        $this->page = $newPage;
102
    }
103
104
105
    public function getPageSize(): int
106
    {
107
        return $this->pageSize;
108
    }
109
110
111
    public function setPageSize(int $newPageSize): void
112
    {
113
        $this->pageSize = $newPageSize;
114
    }
115
116
117
    public function getQuery(): string
118
    {
119
        return $this->query;
120
    }
121
122
123
    /** @return array<\Suilven\FreeTextSearch\Container\Facet> */
124
    public function getFacets(): array
125
    {
126
        return $this->facets;
127
    }
128
129
130
    public function setQuery(string $newQuery): void
131
    {
132
        $this->query = $newQuery;
133
    }
134
135
136
    public function setRecords(ArrayList $newRecords): void
137
    {
138
        $this->records = $newRecords;
139
    }
140
141
142
    public function getRecords(): \SilverStripe\ORM\ArrayList
143
    {
144
        return \is_null($this->records)
145
            ? new ArrayList([])
146
            : $this->records;
147
    }
148
149
150
    /** Accessor to the suggestions
151
     *
152
     * @return array<string>
153
     */
154
    public function getSuggestions(): array
155
    {
156
        return $this->suggestions;
157
    }
158
159
160
    /** @param array<string> $newSuggestions */
161
    public function setSuggestions(array $newSuggestions): void
162
    {
163
        $this->suggestions = $newSuggestions;
164
    }
165
166
167
    public function getTime(): float
168
    {
169
        return $this->time;
170
    }
171
172
173
    public function setTime(float $newTime): void
174
    {
175
        $this->time = $newTime;
176
    }
177
178
179
    public function getSimilarTo(): ?\SilverStripe\ORM\DataObject
180
    {
181
        return $this->searchSimilarTo;
182
    }
183
184
185
    public function setSimilarTo(?\SilverStripe\ORM\DataObject $dataObject): void
186
    {
187
        $this->searchSimilarTo = $dataObject;
188
    }
189
}
190