Commit 2053bb76 authored by Bas de Nooijer's avatar Bas de Nooijer

Simplified example using the new event dispatcher

parent ddd69e3f
<?php <?php
require(__DIR__.'/init.php'); require(__DIR__.'/init.php');
// this very simple plugin is used to show some events use Solarium\Plugin\BufferedAdd\Event\Events;
class simpleDebug extends Solarium\Core\Plugin use Solarium\Plugin\BufferedAdd\Event\PreFlush as PreFlushEvent;
{
protected $_output = array();
public function display()
{
echo implode('<br/>', $this->_output);
}
public function eventBufferedAddFlushStart($buffer) {
$this->_output[] = 'Flushing buffer (' . count($buffer) . 'docs)';
}
}
htmlHeader(); htmlHeader();
...@@ -24,9 +11,13 @@ $client = new Solarium\Client($config); ...@@ -24,9 +11,13 @@ $client = new Solarium\Client($config);
$buffer = $client->getPlugin('bufferedadd'); $buffer = $client->getPlugin('bufferedadd');
$buffer->setBufferSize(10); // this is quite low, in most cases you can use a much higher value $buffer->setBufferSize(10); // this is quite low, in most cases you can use a much higher value
// also register a plugin for outputting events // also register an event hook to display what is happening
$debug = new simpleDebug(); $client->getEventDispatcher()->addListener(
$client->registerPlugin('debugger', $debug); Events::PRE_FLUSH,
function(PreFlushEvent $event){
echo 'Flushing buffer (' . count($event->getBuffer()) . 'docs)<br/>';
}
);
// let's insert 25 docs // let's insert 25 docs
for ($i=1; $i<=25; $i++) { for ($i=1; $i<=25; $i++) {
...@@ -46,7 +37,6 @@ for ($i=1; $i<=25; $i++) { ...@@ -46,7 +37,6 @@ for ($i=1; $i<=25; $i++) {
// manually flush the remainder. Alternatively you can use the commit method if you want to include a commit command. // manually flush the remainder. Alternatively you can use the commit method if you want to include a commit command.
$buffer->flush(); $buffer->flush();
// In total 3 flushes (requests) have been sent to Solr. This should be visible in this output: // In total 3 flushes (requests) have been sent to Solr. This should be visible in the output of the event hook.
$debug->display();
htmlFooter(); htmlFooter();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment