1 | <?php |
||
2 | /** |
||
3 | * Trait GetterSetterTrait|Firesphere\SolrSearch\Traits\GetterSetterTrait Getters and setters that are duplicate among |
||
4 | * classes like {@link \Firesphere\SolrSearch\Indexes\BaseIndex} and {@link \Firesphere\SolrSearch\Queries\BaseQuery} |
||
5 | * |
||
6 | * @package Firesphere\Solr\Search |
||
7 | * @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo |
||
8 | * @copyright Copyright (c) 2018 - now() Firesphere & Sheepy |
||
9 | */ |
||
10 | |||
11 | namespace Firesphere\SolrSearch\Traits; |
||
12 | |||
13 | /** |
||
14 | * Trait GetterSetterTrait for getting and setting data |
||
15 | * |
||
16 | * Getters and setters shared between the Index and Query |
||
17 | * |
||
18 | * @package Firesphere\Solr\Search |
||
19 | */ |
||
20 | trait GetterSetterTrait |
||
21 | { |
||
22 | /** |
||
23 | * @var array Classes to use |
||
24 | */ |
||
25 | protected $class = []; |
||
26 | |||
27 | /** |
||
28 | * Sets boosting at _index_ time or _query_ time. Depending on the usage of this trait |
||
29 | * [ |
||
30 | * 'FieldName' => 2, |
||
31 | * ] |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $boostedFields = []; |
||
36 | |||
37 | /** |
||
38 | * Format: |
||
39 | * SiteTree::class => [ |
||
40 | * 'BaseClass' => SiteTree::class, |
||
41 | * 'Field' => 'ChannelID', |
||
42 | * 'Title' => 'Channel' |
||
43 | * ], |
||
44 | * Object::class => [ |
||
45 | * 'BaseClass' => Object::class, |
||
46 | * 'Field' => 'Relation.ID', |
||
47 | * 'Title' => 'Relation' |
||
48 | * ], |
||
49 | * |
||
50 | * The facets will be applied as a single "AND" query. |
||
51 | * e.g. SiteTree_ChannelID:1 with Object_Relation_ID:5 will not be found, |
||
52 | * if the facet filter requires the SiteTree_ChannelID to be 1 AND Object_Relation_ID to be 3 or 6 |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $facetFields = []; |
||
57 | |||
58 | |||
59 | /** |
||
60 | * Set the classes |
||
61 | * |
||
62 | * @param array $class |
||
63 | * @return $this |
||
64 | */ |
||
65 | 43 | public function setClasses($class): self |
|
66 | { |
||
67 | 43 | $this->class = $class; |
|
68 | |||
69 | 43 | return $this; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * Get classes |
||
74 | * |
||
75 | * @return array |
||
76 | */ |
||
77 | 52 | public function getClasses(): array |
|
78 | { |
||
79 | 52 | return $this->class; |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * Add a class to index or query |
||
84 | * $options is not used anymore, added for backward compatibility |
||
85 | * |
||
86 | * @param $class |
||
87 | * @param array $options unused |
||
88 | * @return $this |
||
89 | */ |
||
90 | 55 | public function addClass($class, $options = []): self |
|
0 ignored issues
–
show
|
|||
91 | { |
||
92 | 55 | $this->class[] = $class; |
|
93 | |||
94 | 55 | return $this; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * Add a boosted field to be boosted at query time |
||
99 | * |
||
100 | * This method is out of place in a way, but it's a shared method |
||
101 | * between Index and Query, thus needs to be here. |
||
102 | * |
||
103 | * @param string $field |
||
104 | * @param array|int $options |
||
105 | * @param int|null $boost |
||
106 | * @return $this |
||
107 | */ |
||
108 | 3 | public function addBoostedField($field, $options = [], $boost = null) |
|
109 | { |
||
110 | 3 | if ($boost === null && is_int($options)) { |
|
111 | 1 | $boost = $options; |
|
112 | } |
||
113 | |||
114 | 3 | $this->boostedFields[$field] = $boost; |
|
115 | |||
116 | 3 | return $this; |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * Get the boosted fields |
||
121 | * |
||
122 | * @return array |
||
123 | */ |
||
124 | 17 | public function getBoostedFields(): array |
|
125 | { |
||
126 | 17 | return $this->boostedFields; |
|
127 | } |
||
128 | |||
129 | /** |
||
130 | * Boosted fields are used at index time, not at query time |
||
131 | * |
||
132 | * @param array $boostedFields |
||
133 | * @return $this |
||
134 | */ |
||
135 | 43 | public function setBoostedFields($boostedFields): self |
|
136 | { |
||
137 | 43 | $this->boostedFields = $boostedFields; |
|
138 | |||
139 | 43 | return $this; |
|
140 | } |
||
141 | |||
142 | /** |
||
143 | * Get the facet fields |
||
144 | * |
||
145 | * @return array |
||
146 | */ |
||
147 | 43 | public function getFacetFields(): array |
|
148 | { |
||
149 | 43 | return $this->facetFields; |
|
150 | } |
||
151 | |||
152 | /** |
||
153 | * Set the facet fields |
||
154 | * |
||
155 | * @param array $facetFields |
||
156 | * @return $this |
||
157 | */ |
||
158 | 42 | public function setFacetFields($facetFields): self |
|
159 | { |
||
160 | 42 | $this->facetFields = $facetFields; |
|
161 | |||
162 | 42 | return $this; |
|
163 | } |
||
164 | } |
||
165 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.