source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/examples/5.3.1-plugin-event-hooks.php @ 7576

Revision 7576, 2.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
2require('init.php');
3
4
5// this very simple plugin shows a timing for each event and display some request debug info
6class basicDebug extends Solarium_Plugin_Abstract
7{
8
9    protected $_start;
10    protected $_output = array();
11
12    public function _initPlugin()
13    {
14        $this->_start = microtime(true);
15    }
16
17    protected function _timer($event)
18    {
19        $time = round(microtime(true) - $this->_start, 5);
20        $this->_output[] = '['.$time.'] ' . $event;
21
22    }
23
24    public function display()
25    {
26        echo implode('<br/>', $this->_output);
27    }
28
29    public function preCreateRequest()
30    {
31        $this->_timer('preCreateRequest');
32    }
33
34    public function postCreateRequest()
35    {
36        $this->_timer('postCreateRequest');
37    }
38
39    // This method uses the aviable param(s) (see plugin abstract class)
40    // You can access or modify data this way
41    public function preExecuteRequest($request)
42    {
43        $this->_timer('preExecuteRequest');
44
45        // this dummy param will be visible in the debug output but will also be used in the actual Solr request
46        $request->addParam('dummyparam', 'dummyvalue');
47
48        $this->_output[] = 'Request URI: ' . $request->getUri();
49    }
50
51    public function postExecuteRequest()
52    {
53        $this->_timer('postExecuteRequest');
54    }
55
56    public function preCreateResult()
57    {
58        $this->_timer('preCreateResult');
59    }
60
61    public function postCreateResult()
62    {
63        $this->_timer('postCreateResult');
64    }
65
66    public function preExecute()
67    {
68        $this->_timer('preExecute');
69    }
70
71    public function postExecute()
72    {
73        $this->_timer('postExecute');
74    }
75
76    public function preCreateQuery()
77    {
78        $this->_timer('preCreateResult');
79    }
80
81    public function postCreateQuery()
82    {
83        $this->_timer('postCreateResult');
84    }
85
86}
87
88
89htmlHeader();
90
91// create a client instance and register the plugin
92$plugin = new basicDebug();
93$client = new Solarium_Client($config);
94$client->registerPlugin('debugger', $plugin);
95
96// execute a select query and display the results
97$query = $client->createSelect();
98$resultset = $client->select($query);
99
100echo 'NumFound: '.$resultset->getNumFound();
101foreach ($resultset as $document) {
102
103    echo '<hr/><table>';
104
105    foreach($document AS $field => $value)
106    {
107        if(is_array($value)) $value = implode(', ', $value);
108
109        echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
110    }
111
112    echo '</table>';
113}
114
115// display the debug plugin output
116echo '<hr/><h1>Plugin output</h1>';
117$plugin->display();
118
119htmlFooter();
Note: See TracBrowser for help on using the repository browser.