1 | <?php |
---|
2 | require('init.php'); |
---|
3 | |
---|
4 | // This is a custom query class that could have some customized logic |
---|
5 | class MyQuery extends Solarium_Query_Select |
---|
6 | { |
---|
7 | // ...customization here... |
---|
8 | } |
---|
9 | |
---|
10 | // this very simple plugin that modifies the default querytype mapping |
---|
11 | class 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 | |
---|
27 | htmlHeader(); |
---|
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 |
---|
37 | echo 'Query class: ' . get_class($query) . '<br/>'; |
---|
38 | |
---|
39 | // execute the query and display the results |
---|
40 | $resultset = $client->select($query); |
---|
41 | echo 'NumFound: '.$resultset->getNumFound(); |
---|
42 | foreach ($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 | |
---|
56 | htmlFooter(); |
---|