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 | * Terms query |
---|
41 | * |
---|
42 | * A terms query provides access to the indexed terms in a field and the number of documents that match each term. |
---|
43 | * This can be useful for doing auto-suggest or other things that operate at the term level instead of the search |
---|
44 | * or document level. Retrieving terms in index order is very fast since the implementation directly uses Lucene's |
---|
45 | * TermEnum to iterate over the term dictionary. |
---|
46 | * |
---|
47 | * @package Solarium |
---|
48 | * @subpackage Query |
---|
49 | */ |
---|
50 | class Solarium_Query_Terms extends Solarium_Query |
---|
51 | { |
---|
52 | |
---|
53 | /** |
---|
54 | * Get type for this query |
---|
55 | * |
---|
56 | * @return string |
---|
57 | */ |
---|
58 | public function getType() |
---|
59 | { |
---|
60 | return Solarium_Client::QUERYTYPE_TERMS; |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * Default options |
---|
65 | * |
---|
66 | * @var array |
---|
67 | */ |
---|
68 | protected $_options = array( |
---|
69 | 'resultclass' => 'Solarium_Result_Terms', |
---|
70 | 'handler' => 'terms', |
---|
71 | ); |
---|
72 | |
---|
73 | /** |
---|
74 | * Set the field name(s) to get the terms from |
---|
75 | * |
---|
76 | * For multiple fields use a comma-separated string |
---|
77 | * |
---|
78 | * @param string $value |
---|
79 | * @return self Provides fluent interface |
---|
80 | */ |
---|
81 | public function setFields($value) |
---|
82 | { |
---|
83 | return $this->_setOption('fields', $value); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * Get the field name(s) to get the terms from |
---|
88 | * |
---|
89 | * @return string |
---|
90 | */ |
---|
91 | public function getFields() |
---|
92 | { |
---|
93 | return $this->getOption('fields'); |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | * Set the lowerbound term to start at |
---|
98 | * |
---|
99 | * @param string $value |
---|
100 | * @return self Provides fluent interface |
---|
101 | */ |
---|
102 | public function setLowerbound($value) |
---|
103 | { |
---|
104 | return $this->_setOption('lowerbound', $value); |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * Get the lowerbound term to start at |
---|
109 | * |
---|
110 | * @return string |
---|
111 | */ |
---|
112 | public function getLowerbound() |
---|
113 | { |
---|
114 | return $this->getOption('lowerbound'); |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | * Set lowerboundinclude |
---|
119 | * |
---|
120 | * @param boolean $value |
---|
121 | * @return self Provides fluent interface |
---|
122 | */ |
---|
123 | public function setLowerboundInclude($value) |
---|
124 | { |
---|
125 | return $this->_setOption('lowerboundinclude', $value); |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * Get lowerboundinclude |
---|
130 | * |
---|
131 | * @return boolean |
---|
132 | */ |
---|
133 | public function getLowerboundInclude() |
---|
134 | { |
---|
135 | return $this->getOption('lowerboundinclude'); |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * Set mincount (the minimum doc frequency for terms in order to be included) |
---|
140 | * |
---|
141 | * @param integer $value |
---|
142 | * @return self Provides fluent interface |
---|
143 | */ |
---|
144 | public function setMinCount($value) |
---|
145 | { |
---|
146 | return $this->_setOption('mincount', $value); |
---|
147 | } |
---|
148 | |
---|
149 | /** |
---|
150 | * Get mincount |
---|
151 | * |
---|
152 | * @return integer |
---|
153 | */ |
---|
154 | public function getMinCount() |
---|
155 | { |
---|
156 | return $this->getOption('mincount'); |
---|
157 | } |
---|
158 | |
---|
159 | /** |
---|
160 | * Set maxcount (the maximum doc frequency for terms in order to be included) |
---|
161 | * |
---|
162 | * @param integer $value |
---|
163 | * @return self Provides fluent interface |
---|
164 | */ |
---|
165 | public function setMaxCount($value) |
---|
166 | { |
---|
167 | return $this->_setOption('maxcount', $value); |
---|
168 | } |
---|
169 | |
---|
170 | /** |
---|
171 | * Get maxcount |
---|
172 | * |
---|
173 | * @return integer |
---|
174 | */ |
---|
175 | public function getMaxCount() |
---|
176 | { |
---|
177 | return $this->getOption('maxcount'); |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * Set prefix for terms |
---|
182 | * |
---|
183 | * @param string $value |
---|
184 | * @return self Provides fluent interface |
---|
185 | */ |
---|
186 | public function setPrefix($value) |
---|
187 | { |
---|
188 | return $this->_setOption('prefix', $value); |
---|
189 | } |
---|
190 | |
---|
191 | /** |
---|
192 | * Get maxcount |
---|
193 | * |
---|
194 | * @return string |
---|
195 | */ |
---|
196 | public function getPrefix() |
---|
197 | { |
---|
198 | return $this->getOption('prefix'); |
---|
199 | } |
---|
200 | |
---|
201 | /** |
---|
202 | * Set regex to restrict terms |
---|
203 | * |
---|
204 | * @param string $value |
---|
205 | * @return self Provides fluent interface |
---|
206 | */ |
---|
207 | public function setRegex($value) |
---|
208 | { |
---|
209 | return $this->_setOption('regex', $value); |
---|
210 | } |
---|
211 | |
---|
212 | /** |
---|
213 | * Get regex |
---|
214 | * |
---|
215 | * @return string |
---|
216 | */ |
---|
217 | public function getRegex() |
---|
218 | { |
---|
219 | return $this->getOption('regex'); |
---|
220 | } |
---|
221 | |
---|
222 | /** |
---|
223 | * Set regex flags |
---|
224 | * |
---|
225 | * Use a comma-separated string for multiple entries |
---|
226 | * |
---|
227 | * @param string $value |
---|
228 | * @return self Provides fluent interface |
---|
229 | */ |
---|
230 | public function setRegexFlags($value) |
---|
231 | { |
---|
232 | return $this->_setOption('regexflags', $value); |
---|
233 | } |
---|
234 | |
---|
235 | /** |
---|
236 | * Get regex flags |
---|
237 | * |
---|
238 | * @return string |
---|
239 | */ |
---|
240 | public function getRegexFlags() |
---|
241 | { |
---|
242 | return $this->getOption('regexflags'); |
---|
243 | } |
---|
244 | |
---|
245 | /** |
---|
246 | * Set limit |
---|
247 | * |
---|
248 | * If < 0 all terms are included |
---|
249 | * |
---|
250 | * @param integer $value |
---|
251 | * @return self Provides fluent interface |
---|
252 | */ |
---|
253 | public function setLimit($value) |
---|
254 | { |
---|
255 | return $this->_setOption('limit', $value); |
---|
256 | } |
---|
257 | |
---|
258 | /** |
---|
259 | * Get limit |
---|
260 | * |
---|
261 | * @return integer |
---|
262 | */ |
---|
263 | public function getLimit() |
---|
264 | { |
---|
265 | return $this->getOption('limit'); |
---|
266 | } |
---|
267 | |
---|
268 | /** |
---|
269 | * Set the upperbound term to start at |
---|
270 | * |
---|
271 | * @param string $value |
---|
272 | * @return self Provides fluent interface |
---|
273 | */ |
---|
274 | public function setUpperbound($value) |
---|
275 | { |
---|
276 | return $this->_setOption('upperbound', $value); |
---|
277 | } |
---|
278 | |
---|
279 | /** |
---|
280 | * Get the upperbound term to start at |
---|
281 | * |
---|
282 | * @return string |
---|
283 | */ |
---|
284 | public function getUpperbound() |
---|
285 | { |
---|
286 | return $this->getOption('upperbound'); |
---|
287 | } |
---|
288 | |
---|
289 | /** |
---|
290 | * Set upperboundinclude |
---|
291 | * |
---|
292 | * @param boolean $value |
---|
293 | * @return self Provides fluent interface |
---|
294 | */ |
---|
295 | public function setUpperboundInclude($value) |
---|
296 | { |
---|
297 | return $this->_setOption('upperboundinclude', $value); |
---|
298 | } |
---|
299 | |
---|
300 | /** |
---|
301 | * Get upperboundinclude |
---|
302 | * |
---|
303 | * @return boolean |
---|
304 | */ |
---|
305 | public function getUpperboundInclude() |
---|
306 | { |
---|
307 | return $this->getOption('upperboundinclude'); |
---|
308 | } |
---|
309 | |
---|
310 | /** |
---|
311 | * Set raw option |
---|
312 | * |
---|
313 | * @param boolean $value |
---|
314 | * @return self Provides fluent interface |
---|
315 | */ |
---|
316 | public function setRaw($value) |
---|
317 | { |
---|
318 | return $this->_setOption('raw', $value); |
---|
319 | } |
---|
320 | |
---|
321 | /** |
---|
322 | * Get raw option |
---|
323 | * |
---|
324 | * @return boolean |
---|
325 | */ |
---|
326 | public function getRaw() |
---|
327 | { |
---|
328 | return $this->getOption('raw'); |
---|
329 | } |
---|
330 | |
---|
331 | /** |
---|
332 | * Set sort option |
---|
333 | * |
---|
334 | * @param string $value |
---|
335 | * @return self Provides fluent interface |
---|
336 | */ |
---|
337 | public function setSort($value) |
---|
338 | { |
---|
339 | return $this->_setOption('sort', $value); |
---|
340 | } |
---|
341 | |
---|
342 | /** |
---|
343 | * Get sort option |
---|
344 | * |
---|
345 | * @return string |
---|
346 | */ |
---|
347 | public function getSort() |
---|
348 | { |
---|
349 | return $this->getOption('sort'); |
---|
350 | } |
---|
351 | |
---|
352 | } |
---|