[7588] | 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 MoreLikeThis request |
---|
| 44 | * |
---|
| 45 | * @package Solarium |
---|
| 46 | * @subpackage Client |
---|
| 47 | */ |
---|
| 48 | class Solarium_Client_RequestBuilder_MoreLikeThis |
---|
| 49 | extends Solarium_Client_RequestBuilder_Select |
---|
| 50 | { |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * Build request for a MoreLikeThis query |
---|
| 54 | * |
---|
| 55 | * @param Solarium_Query_MoreLikeThis $query |
---|
| 56 | * @return Solarium_Client_Request |
---|
| 57 | */ |
---|
| 58 | public function build($query) |
---|
| 59 | { |
---|
| 60 | $request = parent::build($query); |
---|
| 61 | |
---|
| 62 | // add mlt params to request |
---|
| 63 | $request->addParam('mlt.interestingTerms', $query->getInterestingTerms()); |
---|
| 64 | $request->addParam('mlt.match.include', $query->getMatchInclude()); |
---|
| 65 | $request->addParam('mlt.match.offset', $query->getStart()); |
---|
| 66 | $request->addParam('mlt.fl', $query->getMltFields()); |
---|
| 67 | $request->addParam('mlt.mintf', $query->getMinimumTermFrequency()); |
---|
| 68 | $request->addParam('mlt.mindf', $query->getMinimumDocumentFrequency()); |
---|
| 69 | $request->addParam('mlt.minwl', $query->getMinimumWordLength()); |
---|
| 70 | $request->addParam('mlt.maxwl', $query->getMaximumWordLength()); |
---|
| 71 | $request->addParam('mlt.maxqt', $query->getMaximumQueryTerms()); |
---|
| 72 | $request->addParam('mlt.maxntp', $query->getMaximumNumberOfTokens()); |
---|
| 73 | $request->addParam('mlt.boost', $query->getBoost()); |
---|
| 74 | $request->addParam('mlt.qf', $query->getQueryFields()); |
---|
| 75 | |
---|
| 76 | // convert query to stream if necessary |
---|
| 77 | if (true === $query->getQueryStream()) { |
---|
| 78 | $request->removeParam('q'); |
---|
| 79 | $request->setRawData($query->getQuery()); |
---|
| 80 | $request->setMethod(Solarium_Client_Request::METHOD_POST); |
---|
| 81 | $request->addHeader('Content-Type: text/plain; charset=utf-8'); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | return $request; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | } |
---|