Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
2053bb76
Commit
2053bb76
authored
Aug 07, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified example using the new event dispatcher
parent
ddd69e3f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
20 deletions
+10
-20
examples/7.5-plugin-bufferedadd.php
examples/7.5-plugin-bufferedadd.php
+10
-20
No files found.
examples/7.5-plugin-bufferedadd.php
View file @
2053bb76
<?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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment