Passed
Push — master ( 2f8bcf...138ef2 )
by Gordon
03:57 queued 02:01
created

SearchResults::setSimilarTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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<string,int|bool|float|string> */
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
    /** @param array<string,int|bool|float|string> $newFacets */
62
    public function setFacets(array $newFacets): void
63
    {
64
        $this->facets = $newFacets;
65
    }
66
67
68
    public function setIndex(string $newIndex): void
69
    {
70
        $this->index = $newIndex;
71
    }
72
73
74
    public function getTotaNumberOfResults(): int
75
    {
76
        return $this->totalNumberOfResults;
77
    }
78
79
80
    public function setTotalNumberOfResults(int $newTotalNumberOfResults): void
81
    {
82
        $this->totalNumberOfResults = $newTotalNumberOfResults;
83
    }
84
85
86
    public function getTotalPages(): int
87
    {
88
        $nPages = \ceil($this->totalNumberOfResults / $this->pageSize);
89
90
        return \intval($nPages);
91
    }
92
93
94
    public function getPage(): int
95
    {
96
        return $this->page;
97
    }
98
99
100
    public function setPage(int $newPage): void
101
    {
102
        $this->page = $newPage;
103
    }
104
105
106
    public function getPageSize(): int
107
    {
108
        return $this->pageSize;
109
    }
110
111
112
    public function setPageSize(int $newPageSize): void
113
    {
114
        $this->pageSize = $newPageSize;
115
    }
116
117
118
    public function getQuery(): string
119
    {
120
        return $this->query;
121
    }
122
123
124
    public function setQuery(string $newQuery): void
125
    {
126
        $this->query = $newQuery;
127
    }
128
129
130
    public function setRecords(ArrayList $newRecords): void
131
    {
132
        $this->records = $newRecords;
133
    }
134
135
136
    public function getRecords(): \SilverStripe\ORM\ArrayList
137
    {
138
        return \is_null($this->records)
139
            ? new ArrayList([])
140
            : $this->records;
141
    }
142
143
144
    /** Accessor to the suggestions
145
     *
146
     * @return array<string>
147
     */
148
    public function getSuggestions(): array
149
    {
150
        return $this->suggestions;
151
    }
152
153
154
    /** @param array<string> $newSuggestions */
155
    public function setSuggestions(array $newSuggestions): void
156
    {
157
        $this->suggestions = $newSuggestions;
158
    }
159
160
161
    public function getTime(): float
162
    {
163
        return $this->time;
164
    }
165
166
167
    public function setTime(float $newTime): void
168
    {
169
        $this->time = $newTime;
170
    }
171
172
173
    public function getSimilarTo(): ?\SilverStripe\ORM\DataObject
174
    {
175
        return $this->searchSimilarTo;
176
    }
177
178
179
    public function setSimilarTo(?\SilverStripe\ORM\DataObject $dataObject): void
180
    {
181
        $this->searchSimilarTo = $dataObject;
182
    }
183
}
184