source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/library/Solarium/Query/Select/Component/Facet/Range.php @ 7576

Revision 7576, 7.5 KB checked in by adir, 11 years ago (diff)

Ticket #000 - Adicionando a integracao de buscas com Solr na base a ser isnerida na comunidade

Line 
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 range
41 *
42 * @link http://wiki.apache.org/solr/SimpleFacetParameters#Facet_by_Range
43 *
44 * @package Solarium
45 * @subpackage Query
46 */
47class Solarium_Query_Select_Component_Facet_Range extends Solarium_Query_Select_Component_Facet
48{
49
50    /**
51     * Value for the 'other' option
52     */
53    const OTHER_BEFORE = 'before';
54
55    /**
56     * Value for the 'other' option
57     */
58    const OTHER_AFTER = 'after';
59
60    /**
61     * Value for the 'other' option
62     */
63    const OTHER_BETWEEN = 'between';
64
65    /**
66     * Value for the 'other' option
67     */
68    const OTHER_ALL = 'all';
69
70    /**
71     * Value for the 'other' option
72     */
73    const OTHER_NONE = 'none';
74
75    /**
76     * Value for the 'include' option
77     */
78    const INCLUDE_LOWER = 'lower';
79
80    /**
81     * Value for the 'include' option
82     */
83    const INCLUDE_UPPER = 'upper';
84
85    /**
86     * Value for the 'include' option
87     */
88    const INCLUDE_EDGE = 'edge';
89
90    /**
91     * Value for the 'include' option
92     */
93    const INCLUDE_OUTER = 'outer';
94
95    /**
96     * Value for the 'include' option
97     */
98    const INCLUDE_ALL = 'all';
99
100    /**
101     * Initialize options
102     *
103     * Several options need some extra checks or setup work, for these options
104     * the setters are called.
105     *
106     * @return void
107     */
108    protected function _init()
109    {
110        parent::_init();
111
112        foreach ($this->_options AS $name => $value) {
113            switch ($name) {
114                case 'include':
115                    $this->setInclude($value);
116                    break;
117                case 'other':
118                    $this->setOther($value);
119                    break;
120            }
121        }
122    }
123
124    /**
125     * Get the facet type
126     *
127     * @return string
128     */
129    public function getType()
130    {
131        return Solarium_Query_Select_Component_FacetSet::FACET_RANGE;
132    }
133   
134    /**
135     * Set the field name
136     *
137     * @param string $field
138     * @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
139     */
140    public function setField($field)
141    {
142        return $this->_setOption('field', $field);
143    }
144
145    /**
146     * Get the field name
147     *
148     * @return string
149     */
150    public function getField()
151    {
152        return $this->getOption('field');
153    }
154
155    /**
156     * Set the lower bound of the range
157     *
158     * @param string $start
159     * @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
160     */
161    public function setStart($start)
162    {
163        return $this->_setOption('start', $start);
164    }
165
166    /**
167     * Get the lower bound of the range
168     *
169     * @return string
170     */
171    public function getStart()
172    {
173        return $this->getOption('start');
174    }
175
176    /**
177     * Set the upper bound of the range
178     *
179     * @param string $end
180     * @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
181     */
182    public function setEnd($end)
183    {
184        return $this->_setOption('end', $end);
185    }
186
187    /**
188     * Get the upper bound of the range
189     *
190     * @return string
191     */
192    public function getEnd()
193    {
194        return $this->getOption('end');
195    }
196
197    /**
198     * Set range gap
199     *
200     * The size of each range expressed as a value to be added to the lower bound
201     *
202     * @param string $gap
203     * @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
204     */
205    public function setGap($gap)
206    {
207        return $this->_setOption('gap', $gap);
208    }
209
210    /**
211     * Get range gap
212     *
213     * The size of each range expressed as a value to be added to the lower bound
214     *
215     * @return string
216     */
217    public function getGap()
218    {
219        return $this->getOption('gap');
220    }
221
222    /**
223     * Set hardend option
224     *
225     * A Boolean parameter instructing Solr what to do in the event that facet.range.gap
226     * does not divide evenly between facet.range.start and facet.range.end
227     *
228     * @param boolean $hardend
229     * @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
230     */
231    public function setHardend($hardend)
232    {
233        return $this->_setOption('hardend', $hardend);
234    }
235
236    /**
237     * Get hardend option
238     *
239     * @return boolean
240     */
241    public function getHardend()
242    {
243        return $this->getOption('hardend');
244    }
245
246    /**
247     * Set other counts
248     *
249     * Use one of the constants as value.
250     * If you want to use multiple values supply an array or comma separated string
251     *
252     * @param string|array $other
253     * @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
254     */
255    public function setOther($other)
256    {
257        if (is_array($other)) {
258            $other = implode(',', $other);
259        }
260
261        return $this->_setOption('other', $other);   
262    }
263
264    /**
265     * Get other counts
266     *
267     * In case of multiple values a comma separated string will be returned
268     *
269     * @return string
270     */
271    public function getOther()
272    {
273        return $this->getOption('other');
274    }
275
276    /**
277     * Set include option
278     *
279     * Use one of the constants as value.
280     * If you want to use multiple values supply an array or comma separated string
281     *
282     * @param string|array $include
283     * @return Solarium_Query_Select_Component_Facet_Range Provides fluent interface
284     */
285    public function setInclude($include)
286    {
287        if (is_array($include)) {
288            $include = implode(',', $include);
289        }
290
291        return $this->_setOption('include', $include);
292    }
293
294    /**
295     * Get include option
296     *
297     * In case of multiple values a comma separated string will be returned
298     *
299     * @return string
300     */
301    public function getInclude()
302    {
303        return $this->getOption('include');
304    }
305}
Note: See TracBrowser for help on using the repository browser.