source: sandbox/expresso-solr/expressoMail1_2/solrclient/examples/5.3.2-plugin-solarium-presets.php @ 7588

Revision 7588, 1.3 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// This is a custom query class that could have some customized logic
5class MyQuery extends Solarium_Query_Select
6{
7    // ...customization here...
8}
9
10// this very simple plugin that modifies the default querytype mapping
11class queryCustomizer extends Solarium_Plugin_Abstract
12{
13
14    protected function _initPlugin()
15    {
16        $this->_client->registerQueryType(
17            Solarium_Client::QUERYTYPE_SELECT,
18            'MyQuery',
19            'Solarium_Client_RequestBuilder_Select',
20            'Solarium_Client_ResponseParser_Select'
21        );
22    }
23   
24}
25
26
27htmlHeader();
28
29// create a client instance and register the plugin
30$client = new Solarium_Client($config);
31$client->registerPlugin('querycustomizer', 'queryCustomizer');
32
33// create a select query instance
34$query = $client->createSelect();
35
36// check the query class, it should be our custom query class
37echo 'Query class: ' . get_class($query) . '<br/>';
38
39// execute the query and display the results
40$resultset = $client->select($query);
41echo 'NumFound: '.$resultset->getNumFound();
42foreach ($resultset as $document) {
43
44    echo '<hr/><table>';
45
46    foreach($document AS $field => $value)
47    {
48        if(is_array($value)) $value = implode(', ', $value);
49
50        echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
51    }
52
53    echo '</table>';
54}
55
56htmlFooter();
Note: See TracBrowser for help on using the repository browser.