1 | <?php |
---|
2 | /** |
---|
3 | * Copyright 2011 Bas de Nooijer. |
---|
4 | * Copyright 2011 Gasol Wu. PIXNET Digital Media Corporation. |
---|
5 | * All rights reserved. |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions are met: |
---|
9 | * |
---|
10 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
11 | * this list of conditions and the following disclaimer. |
---|
12 | * |
---|
13 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
14 | * this listof conditions and the following disclaimer in the documentation |
---|
15 | * and/or other materials provided with the distribution. |
---|
16 | * |
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" |
---|
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
27 | * POSSIBILITY OF SUCH DAMAGE. |
---|
28 | * |
---|
29 | * The views and conclusions contained in the software and documentation are |
---|
30 | * those of the authors and should not be interpreted as representing official |
---|
31 | * policies, either expressed or implied, of the copyright holder. |
---|
32 | * |
---|
33 | * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> |
---|
34 | * @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com> |
---|
35 | * @license http://github.com/basdenooijer/solarium/raw/master/COPYING |
---|
36 | * @link http://www.solarium-project.org/ |
---|
37 | * |
---|
38 | * @package Solarium |
---|
39 | * @subpackage Client |
---|
40 | */ |
---|
41 | |
---|
42 | /** |
---|
43 | * Build a Terms query request |
---|
44 | * |
---|
45 | * @package Solarium |
---|
46 | * @subpackage Client |
---|
47 | */ |
---|
48 | class Solarium_Client_RequestBuilder_Terms extends Solarium_Client_RequestBuilder |
---|
49 | { |
---|
50 | |
---|
51 | /** |
---|
52 | * Build request for a Terms query |
---|
53 | * |
---|
54 | * @param Solarium_Query_Terms $query |
---|
55 | * @return Solarium_Client_Request |
---|
56 | */ |
---|
57 | public function build($query) |
---|
58 | { |
---|
59 | $request = parent::build($query); |
---|
60 | $request->addParam('terms', true); |
---|
61 | $request->addParam('terms.lower', $query->getLowerbound()); |
---|
62 | $request->addParam('terms.lower.incl', $query->getLowerboundInclude()); |
---|
63 | $request->addParam('terms.mincount', $query->getMinCount()); |
---|
64 | $request->addParam('terms.maxcount', $query->getMaxCount()); |
---|
65 | $request->addParam('terms.prefix', $query->getPrefix()); |
---|
66 | $request->addParam('terms.regex', $query->getRegex()); |
---|
67 | $request->addParam('terms.limit', $query->getLimit()); |
---|
68 | $request->addParam('terms.upper', $query->getUpperbound()); |
---|
69 | $request->addParam('terms.upper.incl', $query->getUpperboundInclude()); |
---|
70 | $request->addParam('terms.raw', $query->getRaw()); |
---|
71 | $request->addParam('terms.sort', $query->getSort()); |
---|
72 | |
---|
73 | $fields = explode(',', $query->getFields()); |
---|
74 | foreach ($fields as $field) { |
---|
75 | $request->addParam('terms.fl', trim($field)); |
---|
76 | } |
---|
77 | |
---|
78 | if ($query->getRegexFlags() !== null) { |
---|
79 | $flags = explode(',', $query->getRegexFlags()); |
---|
80 | foreach ($flags as $flag) { |
---|
81 | $request->addParam('terms.regex.flag', trim($flag)); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | return $request; |
---|
86 | } |
---|
87 | |
---|
88 | } |
---|