1 | <?php |
---|
2 | /** |
---|
3 | * Copyright 2011 Bas de Nooijer. All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions are met: |
---|
7 | * |
---|
8 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
9 | * this list of conditions and the following disclaimer. |
---|
10 | * |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
12 | * this listof conditions and the following disclaimer in the documentation |
---|
13 | * and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" |
---|
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
25 | * POSSIBILITY OF SUCH DAMAGE. |
---|
26 | * |
---|
27 | * The views and conclusions contained in the software and documentation are |
---|
28 | * those of the authors and should not be interpreted as representing official |
---|
29 | * policies, either expressed or implied, of the copyright holder. |
---|
30 | * |
---|
31 | * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> |
---|
32 | * @license http://github.com/basdenooijer/solarium/raw/master/COPYING |
---|
33 | * @link http://www.solarium-project.org/ |
---|
34 | * |
---|
35 | * @package Solarium |
---|
36 | * @subpackage Query |
---|
37 | */ |
---|
38 | |
---|
39 | /** |
---|
40 | * Facet query |
---|
41 | * |
---|
42 | * @link http://wiki.apache.org/solr/SimpleFacetParameters#Field_Value_Faceting_Parameters |
---|
43 | * |
---|
44 | * @package Solarium |
---|
45 | * @subpackage Query |
---|
46 | */ |
---|
47 | class Solarium_Query_Select_Component_Facet_Field extends Solarium_Query_Select_Component_Facet |
---|
48 | { |
---|
49 | |
---|
50 | /** |
---|
51 | * Facet sort type index |
---|
52 | */ |
---|
53 | const SORT_INDEX = 'index'; |
---|
54 | |
---|
55 | /** |
---|
56 | * Facet sort type count |
---|
57 | */ |
---|
58 | const SORT_COUNT = 'count'; |
---|
59 | |
---|
60 | /** |
---|
61 | * Facet method enum |
---|
62 | */ |
---|
63 | const METHOD_ENUM = 'enum'; |
---|
64 | |
---|
65 | /** |
---|
66 | * Facet method fc |
---|
67 | */ |
---|
68 | const METHOD_FC = 'fc'; |
---|
69 | |
---|
70 | /** |
---|
71 | * Default options |
---|
72 | * |
---|
73 | * @var array |
---|
74 | */ |
---|
75 | protected $_options = array( |
---|
76 | 'field' => 'id' |
---|
77 | ); |
---|
78 | |
---|
79 | /** |
---|
80 | * Get the facet type |
---|
81 | * |
---|
82 | * @return string |
---|
83 | */ |
---|
84 | public function getType() |
---|
85 | { |
---|
86 | return Solarium_Query_Select_Component_FacetSet::FACET_FIELD; |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * Set the field name |
---|
91 | * |
---|
92 | * @param string $field |
---|
93 | * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface |
---|
94 | */ |
---|
95 | public function setField($field) |
---|
96 | { |
---|
97 | return $this->_setOption('field', $field); |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * Get the field name |
---|
102 | * |
---|
103 | * @return string |
---|
104 | */ |
---|
105 | public function getField() |
---|
106 | { |
---|
107 | return $this->getOption('field'); |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * Set the facet sort order |
---|
112 | * |
---|
113 | * Use one of the SORT_* constants as the value |
---|
114 | * |
---|
115 | * @param string $sort |
---|
116 | * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface |
---|
117 | */ |
---|
118 | public function setSort($sort) |
---|
119 | { |
---|
120 | return $this->_setOption('sort', $sort); |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | * Get the facet sort order |
---|
125 | * |
---|
126 | * @return string |
---|
127 | */ |
---|
128 | public function getSort() |
---|
129 | { |
---|
130 | return $this->getOption('sort'); |
---|
131 | } |
---|
132 | |
---|
133 | /** |
---|
134 | * Limit the terms for faceting by a prefix |
---|
135 | * |
---|
136 | * @param string $prefix |
---|
137 | * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface |
---|
138 | */ |
---|
139 | public function setPrefix($prefix) |
---|
140 | { |
---|
141 | return $this->_setOption('prefix', $prefix); |
---|
142 | } |
---|
143 | |
---|
144 | /** |
---|
145 | * Get the facet prefix |
---|
146 | * |
---|
147 | * @return string |
---|
148 | */ |
---|
149 | public function getPrefix() |
---|
150 | { |
---|
151 | return $this->getOption('prefix'); |
---|
152 | } |
---|
153 | |
---|
154 | /** |
---|
155 | * Set the facet limit |
---|
156 | * |
---|
157 | * @param int $limit |
---|
158 | * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface |
---|
159 | */ |
---|
160 | public function setLimit($limit) |
---|
161 | { |
---|
162 | return $this->_setOption('limit', $limit); |
---|
163 | } |
---|
164 | |
---|
165 | /** |
---|
166 | * Get the facet limit |
---|
167 | * |
---|
168 | * @return string |
---|
169 | */ |
---|
170 | public function getLimit() |
---|
171 | { |
---|
172 | return $this->getOption('limit'); |
---|
173 | } |
---|
174 | |
---|
175 | /** |
---|
176 | * Set the facet offset |
---|
177 | * |
---|
178 | * @param int $offset |
---|
179 | * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface |
---|
180 | */ |
---|
181 | public function setOffset($offset) |
---|
182 | { |
---|
183 | return $this->_setOption('offset', $offset); |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | * Get the facet offset |
---|
188 | * |
---|
189 | * @return int |
---|
190 | */ |
---|
191 | public function getOffset() |
---|
192 | { |
---|
193 | return $this->getOption('offset'); |
---|
194 | } |
---|
195 | |
---|
196 | /** |
---|
197 | * Set the facet mincount |
---|
198 | * |
---|
199 | * @param int $minCount |
---|
200 | * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface |
---|
201 | */ |
---|
202 | public function setMinCount($minCount) |
---|
203 | { |
---|
204 | return $this->_setOption('mincount', $minCount); |
---|
205 | } |
---|
206 | |
---|
207 | /** |
---|
208 | * Get the facet mincount |
---|
209 | * |
---|
210 | * @return int |
---|
211 | */ |
---|
212 | public function getMinCount() |
---|
213 | { |
---|
214 | return $this->getOption('mincount'); |
---|
215 | } |
---|
216 | |
---|
217 | /** |
---|
218 | * Set the missing count option |
---|
219 | * |
---|
220 | * @param boolean $missing |
---|
221 | * @return Solarium_Query_Select_Component_Facet_Field Provides fluent interface |
---|
222 | */ |
---|
223 | public function setMissing($missing) |
---|
224 | { |
---|
225 | return $this->_setOption('missing', $missing); |
---|
226 | } |
---|
227 | |
---|
228 | /** |
---|
229 | * Get the facet missing option |
---|
230 | * |
---|
231 | * @return boolean |
---|
232 | */ |
---|
233 | public function getMissing() |
---|
234 | { |
---|
235 | return $this->getOption('missing'); |
---|
236 | } |
---|
237 | |
---|
238 | /** |
---|
239 | * Set the facet method |
---|
240 | * |
---|
241 | * Use one of the METHOD_* constants as value |
---|
242 | * |
---|
243 | * @param string $method |
---|
244 | * @return Solarium_Query_Select_Facet_Field Provides fluent interface |
---|
245 | */ |
---|
246 | public function setMethod($method) |
---|
247 | { |
---|
248 | return $this->_setOption('method', $method); |
---|
249 | } |
---|
250 | |
---|
251 | /** |
---|
252 | * Get the facet method |
---|
253 | * |
---|
254 | * @return string |
---|
255 | */ |
---|
256 | public function getMethod() |
---|
257 | { |
---|
258 | return $this->getOption('method'); |
---|
259 | } |
---|
260 | |
---|
261 | } |
---|