forked from solariumphp/solarium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5.3.2-plugin-solarium-presets.php
56 lines (43 loc) · 1.33 KB
/
5.3.2-plugin-solarium-presets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
require(__DIR__.'/init.php');
use Solarium\Client;
use Solarium\Core\Plugin\AbstractPlugin;
use Solarium\QueryType\Select\Query\Query as Select;
// This is a custom query class that could have some customized logic
class MyQuery extends Select
{
// ...customization here...
}
// this very simple plugin that modifies the default querytype mapping
class QueryCustomizer extends AbstractPlugin
{
public function initPlugin($client, $options)
{
$client->registerQueryType(
Client::QUERY_SELECT,
'MyQuery'
);
}
}
htmlHeader();
// create a client instance and register the plugin
$client = new Client($config);
$client->registerPlugin('querycustomizer', 'QueryCustomizer');
// create a select query instance
$query = $client->createSelect();
// check the query class, it should be our custom query class
echo 'Query class: ' . get_class($query) . '<br/>';
// execute the query and display the results
$resultset = $client->select($query);
echo 'NumFound: '.$resultset->getNumFound();
foreach ($resultset as $document) {
echo '<hr/><table>';
foreach ($document as $field => $value) {
if (is_array($value)) {
$value = implode(', ', $value);
}
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table>';
}
htmlFooter();