source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/examples/2.4.2-analysis-field.php @ 7576

Revision 7576, 2.6 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
3require('init.php');
4htmlHeader();
5
6// create a client instance
7$client = new Solarium_Client($config);
8
9// get an analysis document query
10$query = $client->createAnalysisField();
11
12$query->setShowMatch(true);
13$query->setFieldName('cat,title');
14$query->setFieldType('text_general');
15$query->setFieldValue('Apple 60 GB iPod with Video Playback Black');
16$query->setQuery('ipod');
17
18// this executes the query and returns the result
19$results = $client->analyze($query);
20
21// show the results
22foreach ($results as $result) {
23
24    echo '<hr><h2>Result list: ' . $result->getName() . '</h2>';
25
26    foreach ($result as $item) {
27
28        echo '<h3>Item: ' . $item->getName() . '</h3>';
29
30        $indexAnalysis = $item->getIndexAnalysis();
31        if (!empty($indexAnalysis)) {
32            echo '<h4>Index Analysis</h4>';
33            foreach ($indexAnalysis as $classes) {
34
35                echo '<h5>'.$classes->getName().'</h5>';
36
37                foreach($classes as $result) {
38                    echo 'Text: ' . $result->getText() . '<br/>';
39                    echo 'Raw text: ' . $result->getRawText() . '<br/>';
40                    echo 'Start: ' . $result->getStart() . '<br/>';
41                    echo 'End: ' . $result->getEnd() . '<br/>';
42                    echo 'Position: ' . $result->getPosition() . '<br/>';
43                    echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>';
44                    echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>';
45                    echo 'Match: ' . var_export($result->getMatch(),true) . '<br/>';
46                    echo '-----------<br/>';
47                }
48            }
49        }
50
51        $queryAnalysis = $item->getQueryAnalysis();
52        if (!empty($queryAnalysis)) {
53            echo '<h4>Query Analysis</h4>';
54            foreach ($queryAnalysis as $classes) {
55
56                echo '<h5>'.$classes->getName().'</h5>';
57
58                foreach($classes as $result) {
59                    echo 'Text: ' . $result->getText() . '<br/>';
60                    echo 'Raw text: ' . $result->getRawText() . '<br/>';
61                    echo 'Start: ' . $result->getStart() . '<br/>';
62                    echo 'End: ' . $result->getEnd() . '<br/>';
63                    echo 'Position: ' . $result->getPosition() . '<br/>';
64                    echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>';
65                    echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>';
66                    echo 'Match: ' . var_export($result->getMatch(),true) . '<br/>';
67                    echo '-----------<br/>';
68                }
69            }
70        }
71    }
72}
73
74htmlFooter();
Note: See TracBrowser for help on using the repository browser.