|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Firesphere\SolrSearch\Traits; |
|
5
|
|
|
|
|
6
|
|
|
use SilverStripe\Dev\Deprecation; |
|
7
|
|
|
|
|
8
|
|
|
trait GetterSetterTrait |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var array |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $class = []; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Sets boosting at _index_ time or _query_ time. Depending on the usage of this trait |
|
17
|
|
|
* [ |
|
18
|
|
|
* 'FieldName' => 2, |
|
19
|
|
|
* ] |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $boostedFields = []; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Format: |
|
26
|
|
|
* SiteTree::class => [ |
|
27
|
|
|
* 'Field' => 'SiteTree_ChannelID', |
|
28
|
|
|
* 'Title' => 'Channel' |
|
29
|
|
|
* ], |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $facetFields = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param array $class |
|
36
|
|
|
* @return $this |
|
37
|
|
|
*/ |
|
38
|
58 |
|
public function setClasses($class): self |
|
39
|
|
|
{ |
|
40
|
58 |
|
$this->class = $class; |
|
41
|
|
|
|
|
42
|
58 |
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* $options is not used anymore, added for backward compatibility |
|
47
|
|
|
* @param $class |
|
48
|
|
|
* @param array $options unused |
|
49
|
|
|
* @return $this |
|
50
|
|
|
*/ |
|
51
|
59 |
|
public function addClass($class, $options = array()): self |
|
52
|
|
|
{ |
|
53
|
59 |
|
if (count($options)) { |
|
54
|
|
|
Deprecation::notice('5.0', 'Options are not used anymore'); |
|
55
|
|
|
} |
|
56
|
59 |
|
$this->class[] = $class; |
|
57
|
|
|
|
|
58
|
59 |
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return array |
|
63
|
|
|
*/ |
|
64
|
63 |
|
public function getClasses(): array |
|
65
|
|
|
{ |
|
66
|
63 |
|
return $this->class; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Add a boosted field to be boosted at query time |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $field |
|
73
|
|
|
* @param array|int $options |
|
74
|
|
|
* @param int|null $boost |
|
75
|
|
|
* @return $this |
|
76
|
|
|
*/ |
|
77
|
2 |
|
public function addBoostedField($field, $options = [], $boost = null): self |
|
78
|
|
|
{ |
|
79
|
2 |
|
if ($boost === null && is_int($options)) { |
|
80
|
1 |
|
$boost = $options; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
2 |
|
$this->boostedFields[$field] = $boost; |
|
84
|
|
|
|
|
85
|
2 |
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
37 |
|
public function getBoostedFields(): array |
|
92
|
|
|
{ |
|
93
|
37 |
|
return $this->boostedFields; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Boosted fields are used at index time, not at query time |
|
98
|
|
|
* |
|
99
|
|
|
* @param array $boostedFields |
|
100
|
|
|
* @return $this |
|
101
|
|
|
*/ |
|
102
|
58 |
|
public function setBoostedFields($boostedFields): self |
|
103
|
|
|
{ |
|
104
|
58 |
|
$this->boostedFields = $boostedFields; |
|
105
|
|
|
|
|
106
|
58 |
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return array |
|
111
|
|
|
*/ |
|
112
|
37 |
|
public function getFacetFields(): array |
|
113
|
|
|
{ |
|
114
|
37 |
|
return $this->facetFields; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param array $facetFields |
|
119
|
|
|
* @return $this |
|
120
|
|
|
*/ |
|
121
|
58 |
|
public function setFacetFields($facetFields): self |
|
122
|
|
|
{ |
|
123
|
58 |
|
$this->facetFields = $facetFields; |
|
124
|
|
|
|
|
125
|
58 |
|
return $this; |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|