source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/library/Solarium/Result/MoreLikeThis.php @ 7576

Revision 7576, 3.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 Gasol Wu. PIXNET Digital Media Corporation.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 *    this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 *    this listof conditions and the following disclaimer in the documentation
14 *    and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * The views and conclusions contained in the software and documentation are
29 * those of the authors and should not be interpreted as representing official
30 * policies, either expressed or implied, of the copyright holder.
31 *
32 * @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com>
33 * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
34 * @link http://www.solarium-project.org/
35 *
36 * @package Solarium
37 * @subpackage Result
38 */
39
40/**
41 * MoreLikeThis query result
42 *
43 * This is the standard resulttype for a moreLikeThis query. Example usage:
44 * <code>
45 * // total solr mlt results
46 * $result->getNumFound();
47 *
48 * // results fetched
49 * count($result);
50 *
51 * // iterate over fetched mlt docs
52 * foreach ($result AS $doc) {
53 *    ....
54 * }
55 * </code>
56 *
57 * @package Solarium
58 * @subpackage Result
59 */
60class Solarium_Result_MoreLikeThis extends Solarium_Result_Select
61{
62    /**
63     * MLT interesting terms
64     */
65    protected $_interestingTerms;
66
67    /**
68     * MLT match document
69     */
70    protected $_match;
71
72    /**
73     * Get MLT interesting terms
74     *
75     * this will show what "interesting" terms are used for the MoreLikeThis
76     * query. These are the top tf/idf terms. NOTE: if you select 'details',
77     * this shows you the term and boost used for each term. Unless
78     * mlt.boost=true all terms will have boost=1.0
79     *
80     * @return array
81     */
82    public function getInterestingTerms()
83    {
84        $query = $this->getQuery();
85        if ('none' == $query->getInterestingTerms()) {
86            throw new Solarium_Exception('interestingterms is none');
87        }
88        $this->_parseResponse();
89        return $this->_interestingTerms;
90    }
91
92    /**
93     * Get matched document
94     *
95     * Only available if matchinclude was set to true in the query.
96     *
97     * @throws Solarium_Exception
98     * @return Solarium_Document
99     */
100    public function getMatch()
101    {
102        $query = $this->getQuery();
103        if (true != $query->getMatchInclude()) {
104            throw new Solarium_Exception('matchinclude was disabled in the MLT query');
105        }
106        $this->_parseResponse();
107        return $this->_match;
108    }
109}
Note: See TracBrowser for help on using the repository browser.