source: sandbox/expresso-solr/expressoMail1_2/solrclient/examples/7.4-plugin-parallelexecution.php @ 7588

Revision 7588, 1.9 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
4htmlHeader();
5
6// create a client instance and autoload the customize request plugin
7$client = new Solarium_Client($config);
8$parallel = $client->getPlugin('parallelexecution');
9
10// Add a delay param to better show the effect, as an example Solr install with
11// only a dozen documents is too fast for good testing
12// This param only works with the correct Solr plugin,
13// see http://www.raspberry.nl/2012/01/04/solr-delay-component/
14// If you don't have to plugin the example still works, just without the delay.
15$customizer = $client->getPlugin('customizerequest');
16$customizer->createCustomization(array(
17    'key' => 'delay',
18    'type' => 'param',
19    'name' => 'delay',
20    'value' => '500',
21    'persistent' => true
22));
23
24// create two queries to execute in an array. Keys are important for fetching the results later!
25$queryInstock = $client->createSelect()->setQuery('inStock:true');
26$queryLowprice = $client->createSelect()->setQuery('price:[1 TO 300]');
27
28// first execute the queries the normal way and time it
29$start = microtime(true);
30$client->execute($queryInstock);
31$client->execute($queryLowprice);
32echo 'Execution time for normal "serial" execution of two queries: ' . round(microtime(true)-$start, 3);
33
34
35echo '<hr/>';
36
37
38// now execute the two queries parallel and time it
39$start = microtime(true);
40$parallel->addQuery('instock', $queryInstock);
41$parallel->addQuery('lowprice', $queryLowprice);
42$results = $parallel->execute();
43echo 'Execution time for parallel execution of two queries: ' . round(microtime(true)-$start, 3);
44
45
46htmlFooter();
47
48// Note: for this example on a default Solr index (with a tiny index) running on localhost the performance gain is
49// minimal to none, sometimes even slightly slower!
50// In a realworld scenario with network latency, a bigger dataset, more complex queries or multiple solr instances the
51// performance gain is much more.
Note: See TracBrowser for help on using the repository browser.