source: sandbox/expresso-solr/expressoMail1_2/solrclient/tests/Solarium/Client/RequestBuilder/Select/Component/HighlightingTest.php @ 7588

Revision 7588, 5.0 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_Client_RequestBuilder_Select_Component_HighlightingTest extends PHPUnit_Framework_TestCase
33{
34
35    public function testBuildComponent()
36    {
37        $builder = new Solarium_Client_RequestBuilder_Select_Component_Highlighting;
38        $request = new Solarium_Client_Request();
39
40        $component = new Solarium_Query_Select_Component_Highlighting();
41        $component->addField('fieldA');
42
43        $field = $component->getField('fieldB');
44        $field->setSnippets(3);
45        $field->setFragSize(25);
46        $field->setMergeContiguous(true);
47        $field->setAlternateField('text');
48        $field->setFormatter('myFormatter');
49        $field->setSimplePrefix('<b>');
50        $field->setSimplePostfix('</b>');
51        $field->setFragmenter('myFragmenter');
52        $field->setUseFastVectorHighlighter(true);
53
54        $component->setSnippets(2);
55        $component->setFragSize(3);
56        $component->setMergeContiguous(true);
57        $component->setRequireFieldMatch(false);
58        $component->setMaxAnalyzedChars(4);
59        $component->setAlternateField('fieldC');
60        $component->setMaxAlternateFieldLength(5);
61        $component->setFormatter('simple');
62        $component->setSimplePrefix('<b>');
63        $component->setSimplePostfix('</b>');
64        $component->setFragmenter('myFragmenter');
65        $component->setFragListBuilder('myFragListBuilder');
66        $component->setFragmentsBuilder('myFragmentsBuilder');
67        $component->setUsePhraseHighlighter(true);
68        $component->setUseFastVectorHighlighter(false);
69        $component->setHighlightMultiTerm(true);
70        $component->setRegexSlop(1.3);
71        $component->setRegexPattern('mypattern');
72        $component->setMaxAnalyzedChars(100);
73        $component->setQuery('text:myvalue');
74        $component->setPhraseLimit(40);
75
76        $request = $builder->buildComponent($component, $request);
77
78        $this->assertEquals(
79            array(
80                'hl' => 'true',
81                'hl.fl' => 'fieldA,fieldB',
82                'hl.snippets' => 2,
83                'hl.fragsize' => 3,
84                'hl.mergeContiguous' => 'true',
85                'hl.requireFieldMatch' => 'false',
86                'hl.maxAnalyzedChars' => 100,
87                'hl.alternateField' => 'fieldC',
88                'hl.maxAlternateFieldLength' => 5,
89                'hl.formatter' => 'simple',
90                'hl.simple.pre' => '<b>',
91                'hl.simple.post' => '</b>',
92                'hl.fragmenter' => 'myFragmenter',
93                'hl.fragListBuilder' => 'myFragListBuilder',
94                'hl.fragmentsBuilder' => 'myFragmentsBuilder',
95                'hl.useFastVectorHighlighter' => 'false',
96                'hl.usePhraseHighlighter' => 'true',
97                'hl.highlightMultiTerm' => 'true',
98                'hl.regex.slop' => 1.3,
99                'hl.regex.pattern' => 'mypattern',
100                'hl.q' => 'text:myvalue',
101                'hl.phraseLimit' => 40,
102                'f.fieldB.hl.snippets' => 3,
103                'f.fieldB.hl.fragsize' => 25,
104                'f.fieldB.hl.mergeContiguous' => 'true',
105                'f.fieldB.hl.alternateField' => 'text',
106                'f.fieldB.hl.formatter' => 'myFormatter',
107                'f.fieldB.hl.simple.pre' => '<b>',
108                'f.fieldB.hl.simple.post' => '</b>',
109                'f.fieldB.hl.fragmenter' => 'myFragmenter',
110                'f.fieldB.hl.useFastVectorHighlighter' => 'true',
111            ),
112            $request->getParams()
113        );
114
115    }
116
117}
Note: See TracBrowser for help on using the repository browser.