Commit 762fd57c authored by Bas de Nooijer's avatar Bas de Nooijer

Added example for distributed search

parent 2ab3d9f1
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium_Client($config);
// get a select query instance
$query = $client->createSelect();
// add distributed search settings
// see http://wiki.apache.org/solr/DistributedSearch#Distributed_Search_Example for setting up two solr instances
$distributedSearch = $query->getDistributedSearch();
$distributedSearch->addShard('shard1', 'localhost:8983/solr');
$distributedSearch->addShard('shard2', 'localhost:7574/solr');
// this executes the query and returns the result
$resultset = $client->select($query);
// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();
// show documents using the resultset iterator
foreach ($resultset as $document) {
echo '<hr/><table>';
// the documents are also iterable, to get all fields
foreach($document AS $field => $value)
{
// this converts multivalue fields to a comma-separated string
if(is_array($value)) $value = implode(', ', $value);
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
}
echo '</table>';
}
htmlFooter();
\ No newline at end of file
......@@ -52,6 +52,7 @@
<li><a href="2.1.5.5-edismax.php">2.1.5.5 Edismax</a></li>
<li><a href="2.1.5.6-grouping-by-field.php">2.1.5.5 Grouping by field</a></li>
<li><a href="2.1.5.7-grouping-by-query.php">2.1.5.6 Grouping by query</a></li>
<li><a href="2.1.5.8-distributed-search.php">2.1.5.6 Distributed search (sharding)</a></li>
</ul>
<li><a href="2.1.6-helper-functions.php">2.1.6 Helper functions</a></li>
<li><a href="2.1.7-query-reuse.php">2.1.7 Query re-use</a></li>
......
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