Passed
Pull Request — master (#188)
by Simon
08:49 queued 06:27
created

BaseQuery::setFacetsMinCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * class BaseQuery|Firesphere\SolrSearch\Queries\BaseQuery Base of a Solr Query
4
 *
5
 * @package Firesphere\SolrSearch\Queries
6
 * @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo
7
 * @copyright Copyright (c) 2018 - now() Firesphere & Sheepy
8
 */
9
10
namespace Firesphere\SolrSearch\Queries;
11
12
use Firesphere\SolrSearch\Traits\BaseQueryTrait;
13
use Firesphere\SolrSearch\Traits\GetterSetterTrait;
14
use SilverStripe\Core\Injector\Injectable;
15
16
/**
17
 * Class BaseQuery is the base of every query executed.
18
 *
19
 * Build a query to execute agains Solr. Uses as simle as possible an interface.
20
 *
21
 * @package Firesphere\SolrSearch\Queries
22
 */
23
class BaseQuery
24
{
25
    use GetterSetterTrait;
26
    use BaseQueryTrait;
27
    use Injectable;
28
    /**
29
     * Pagination start
30
     *
31
     * @var int
32
     */
33
    protected $start = 0;
34
    /**
35
     * Total rows to display
36
     *
37
     * @var int
38
     */
39
    protected $rows = 10;
40
    /**
41
     * Always get the ID. If you don't, you need to implement your own solution
42
     *
43
     * @var array
44
     */
45
    protected $fields = [];
46
    /**
47
     * Sorting
48
     *
49
     * @var array
50
     */
51
    protected $sort = [];
52
    /**
53
     * Enable spellchecking?
54
     *
55
     * @var bool
56
     */
57
    protected $spellcheck = true;
58
    /**
59
     * Follow spellchecking if there are no results
60
     *
61
     * @var bool
62
     */
63
    protected $followSpellcheck = false;
64
    /**
65
     * Minimum results a facet query has to have
66
     *
67
     * @var int
68
     */
69
    protected $facetsMinCount = 0;
70
    /**
71
     * Search terms
72
     *
73
     * @var array
74
     */
75
    protected $terms = [];
76
    /**
77
     * Highlighted items
78
     *
79
     * @var array
80
     */
81
    protected $highlight = [];
82
    /**
83
     * @var array Classes to exclude through hierarchy
84
     */
85
    protected $excludedSubClasses = [];
86
87
    /**
88
     * Get the offset to start
89
     *
90
     * @return int
91
     */
92 8
    public function getStart(): int
93
    {
94 8
        return $this->start;
95
    }
96
97
    /**
98
     * Set the offset to start
99
     *
100
     * @param int $start
101
     * @return $this
102
     */
103 1
    public function setStart($start): self
104
    {
105 1
        $this->start = $start;
106
107 1
        return $this;
108
    }
109
110
    /**
111
     * Get the rows to return
112
     *
113
     * @return int
114
     */
115 8
    public function getRows(): int
116
    {
117 8
        return $this->rows;
118
    }
119
120
    /**
121
     * Set the rows to return
122
     *
123
     * @param int $rows
124
     * @return $this
125
     */
126 1
    public function setRows($rows): self
127
    {
128 1
        $this->rows = $rows;
129
130 1
        return $this;
131
    }
132
133
    /**
134
     * Get the fields to return
135
     *
136
     * @return array
137
     */
138 8
    public function getFields(): array
139
    {
140 8
        return $this->fields;
141
    }
142
143
    /**
144
     * Set fields to be returned
145
     *
146
     * @param array $fields
147
     * @return $this
148
     */
149 1
    public function setFields($fields): self
150
    {
151 1
        $this->fields = $fields;
152
153 1
        return $this;
154
    }
155
156
    /**
157
     * Get the sort fields
158
     *
159
     * @return array
160
     */
161 1
    public function getSort(): array
162
    {
163 1
        return $this->sort;
164
    }
165
166
    /**
167
     * Set the sort fields
168
     *
169
     * @param array $sort
170
     * @return $this
171
     */
172 1
    public function setSort($sort): self
173
    {
174 1
        $this->sort = $sort;
175
176 1
        return $this;
177
    }
178
179
    /**
180
     * Get the facet count minimum to use
181
     *
182
     * @return int
183
     */
184 8
    public function getFacetsMinCount(): int
185
    {
186 8
        return $this->facetsMinCount;
187
    }
188
189
    /**
190
     * Set the minimum count of facets to be returned
191
     *
192
     * @param mixed $facetsMinCount
193
     * @return $this
194
     */
195 1
    public function setFacetsMinCount($facetsMinCount): self
196
    {
197 1
        $this->facetsMinCount = $facetsMinCount;
198
199 1
        return $this;
200
    }
201
202
    /**
203
     * Get the search terms
204
     *
205
     * @return array
206
     */
207 8
    public function getTerms(): array
208
    {
209 8
        return $this->terms;
210
    }
211
212
    /**
213
     * Set the search tearms
214
     *
215
     * @param array $terms
216
     * @return $this
217
     */
218 3
    public function setTerms($terms): self
219
    {
220 3
        $this->terms = $terms;
221
222 3
        return $this;
223
    }
224
225
    /**
226
     * Get the filters
227
     *
228
     * @return array
229
     */
230 8
    public function getFilter(): array
231
    {
232 8
        return $this->filter;
233
    }
234
235
    /**
236
     * Set the query filters
237
     *
238
     * @param array $filter
239
     * @return $this
240
     */
241 1
    public function setFilter($filter): self
242
    {
243 1
        $this->filter = $filter;
244
245 1
        return $this;
246
    }
247
248
    /**
249
     * Get the excludes
250
     *
251
     * @return array
252
     */
253 8
    public function getExclude(): array
254
    {
255 8
        return $this->exclude;
256
    }
257
258
    /**
259
     * Set the query excludes
260
     *
261
     * @param array $exclude
262
     * @return $this
263
     */
264 1
    public function setExclude($exclude): self
265
    {
266 1
        $this->exclude = $exclude;
267
268 1
        return $this;
269
    }
270
271
    /**
272
     * Add a highlight parameter
273
     *
274
     * @param $field
275
     * @return $this
276
     */
277 1
    public function addHighlight($field): self
278
    {
279 1
        $this->highlight[] = $field;
280
281 1
        return $this;
282
    }
283
284
    /**
285
     * Get the highlight parameters
286
     *
287
     * @return array
288
     */
289 8
    public function getHighlight(): array
290
    {
291 8
        return $this->highlight;
292
    }
293
294
    /**
295
     * Set the highlight parameters
296
     *
297
     * @param array $highlight
298
     * @return $this
299
     */
300 2
    public function setHighlight($highlight): self
301
    {
302 2
        $this->highlight = $highlight;
303
304 2
        return $this;
305
    }
306
307
    /**
308
     * Do we have spellchecking
309
     *
310
     * @return bool
311
     */
312 7
    public function hasSpellcheck(): bool
313
    {
314 7
        return $this->spellcheck;
315
    }
316
317
    /**
318
     * Set the spellchecking on this query
319
     *
320
     * @param bool $spellcheck
321
     * @return self
322
     */
323 3
    public function setSpellcheck(bool $spellcheck): self
324
    {
325 3
        $this->spellcheck = $spellcheck;
326
327 3
        return $this;
328
    }
329
330
    /**
331
     * Set if we should follow spellchecking
332
     *
333
     * @param bool $followSpellcheck
334
     * @return BaseQuery
335
     */
336 2
    public function setFollowSpellcheck(bool $followSpellcheck): BaseQuery
337
    {
338 2
        $this->followSpellcheck = $followSpellcheck;
339
340 2
        return $this;
341
    }
342
343
    /**
344
     * Should spellcheck suggestions be followed
345
     *
346
     * @return bool
347
     */
348 7
    public function shouldFollowSpellcheck(): bool
349
    {
350 7
        return $this->followSpellcheck;
351
    }
352
353
    /**
354
     * Get the facet filtering
355
     *
356
     * @return array
357
     */
358 8
    public function getFacetFilter(): array
359
    {
360 8
        return $this->facetFilter;
361
    }
362
363
    /**
364
     * Set the facet filtering
365
     *
366
     * @param array $facetFilter
367
     * @return BaseQuery
368
     */
369 1
    public function setFacetFilter(array $facetFilter): self
370
    {
371 1
        $this->facetFilter = $facetFilter;
372
373 1
        return $this;
374
    }
375
376
    /**
377
     * @return array
378
     */
379 7
    public function getExcludedSubClasses(): array
380
    {
381 7
        return $this->excludedSubClasses;
382
    }
383
384
    /**
385
     * @param array $excludedSubClasses
386
     * @return BaseQuery
387
     */
388
    public function setExcludedSubClasses(array $excludedSubClasses): self
389
    {
390
        $this->excludedSubClasses = $excludedSubClasses;
391
392
        return $this;
393
    }
394
}
395