source: sandbox/expresso-solr/expressoMail1_2/solrclient/tests/Solarium/Query/Select/Component/DisMaxTest.php @ 7588

Revision 7588, 5.9 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
32class Solarium_Query_Select_Component_DisMaxTest extends PHPUnit_Framework_TestCase
33{
34
35    /**
36     * @var Solarium_Query_Select_Component_DisMax
37     */
38    protected $_disMax;
39
40    public function setUp()
41    {
42        $this->_disMax = new Solarium_Query_Select_Component_DisMax;
43    }
44
45    public function testConfigMode()
46    {
47        $options = array(
48            'queryparser' => 'edismax',
49            'queryalternative' => '*:*',
50            'queryfields' => 'title^2.0 description',
51            'minimummatch' => '2.0',
52            'phrasefields' => 'title^2.0 description^3.5',
53            'phraseslop' => 2,
54            'queryphraseslop' => 4,
55            'tie' => 2.1,
56            'boostquery' => 'cat:1^3',
57            'boostfunctions' => 'funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2',
58        );
59
60        $this->_disMax->setOptions($options);
61
62        $this->assertEquals($options['queryparser'], $this->_disMax->getQueryParser());
63        $this->assertEquals($options['queryalternative'], $this->_disMax->getQueryAlternative());
64        $this->assertEquals($options['queryfields'], $this->_disMax->getQueryFields());
65        $this->assertEquals($options['minimummatch'], $this->_disMax->getMinimumMatch());
66        $this->assertEquals($options['phrasefields'], $this->_disMax->getPhraseFields());
67        $this->assertEquals($options['phraseslop'], $this->_disMax->getPhraseSlop());
68        $this->assertEquals($options['queryphraseslop'], $this->_disMax->getQueryPhraseSlop());
69        $this->assertEquals($options['tie'], $this->_disMax->getTie());
70        $this->assertEquals($options['boostquery'], $this->_disMax->getBoostQuery());
71        $this->assertEquals($options['boostfunctions'], $this->_disMax->getBoostFunctions());
72    }
73
74    public function testGetType()
75    {
76        $this->assertEquals(
77            Solarium_Query_Select::COMPONENT_DISMAX,
78            $this->_disMax->getType()
79        );
80    }
81
82    public function testSetAndGetQueryParser()
83    {
84        $value = 'dummyparser';
85        $this->_disMax->setQueryParser($value);
86
87        $this->assertEquals(
88            $value,
89            $this->_disMax->getQueryParser()
90        );
91    }
92
93    public function testSetAndGetQueryAlternative()
94    {
95        $value = '*:*';
96        $this->_disMax->setQueryAlternative($value);
97
98        $this->assertEquals(
99            $value,
100            $this->_disMax->getQueryAlternative()
101        );
102    }
103
104    public function testSetAndGetQueryFields()
105    {
106        $value = 'title^2.0 description';
107        $this->_disMax->setQueryFields($value);
108
109        $this->assertEquals(
110            $value,
111            $this->_disMax->getQueryFields()
112        );
113    }
114
115    public function testSetAndGetMinimumMatch()
116    {
117        $value = '2.0';
118        $this->_disMax->setMinimumMatch($value);
119
120        $this->assertEquals(
121            $value,
122            $this->_disMax->getMinimumMatch()
123        );
124    }
125
126    public function testSetAndGetPhraseFields()
127    {
128        $value = 'title^2.0 description^3.5';
129        $this->_disMax->setPhraseFields($value);
130
131        $this->assertEquals(
132            $value,
133            $this->_disMax->getPhraseFields()
134        );
135    }
136
137    public function testSetAndGetPhraseSlop()
138    {
139        $value = '2';
140        $this->_disMax->setPhraseSlop($value);
141
142        $this->assertEquals(
143            $value,
144            $this->_disMax->getPhraseSlop()
145        );
146    }
147
148    public function testSetAndGetQueryPhraseSlop()
149    {
150        $value = '3';
151        $this->_disMax->setQueryPhraseSlop($value);
152
153        $this->assertEquals(
154            $value,
155            $this->_disMax->getQueryPhraseSlop()
156        );
157    }
158
159    public function testSetAndGetTie()
160    {
161        $value = 2.1;
162        $this->_disMax->setTie($value);
163
164        $this->assertEquals(
165            $value,
166            $this->_disMax->getTie()
167        );
168    }
169
170    public function testSetAndGetBoostQuery()
171    {
172        $value = 'cat:1^3';
173        $this->_disMax->setBoostQuery($value);
174
175        $this->assertEquals(
176            $value,
177            $this->_disMax->getBoostQuery()
178        );
179    }
180
181    public function testSetAndGetBoostFunctions()
182    {
183        $value = 'funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2';
184        $this->_disMax->setBoostFunctions($value);
185
186        $this->assertEquals(
187            $value,
188            $this->_disMax->getBoostFunctions()
189        );
190    }
191   
192}
Note: See TracBrowser for help on using the repository browser.