Skip to content

Instantly share code, notes, and snippets.

@dmouse
Created April 5, 2013 00:57
Show Gist options
  • Save dmouse/5315791 to your computer and use it in GitHub Desktop.
Save dmouse/5315791 to your computer and use it in GitHub Desktop.
Create nested joins in apache solr with solarium. - This sample run with apache solr 4.x. - The nested querys is defined by the key _query_:" ... _query_:\" ... _query_:\" ... \" \" "
<?php
use \Solarium\Client as Client;
$config = array(
'endpoint' => array(
'localhost' => array(
'host' => '127.0.0.1',
'port' => 8080,
'path' => '/solr4/',
)
));
$client = new Client($config);
$select = array();
$select['query'] = 'bundle:a sm_field:string\ with\ spaces _query_:"{!join from=id to=parent} bundle:b _query_:\"{!join from=id to=parent} bundle:c field_boolean:true field_term:Start \"" ds_created:[2013-03-01T00:00:01Z TO 2013-03-31T23:59:59Z]';
$select['fields'] = array('bundle','id');
$select['start'] = 0;
$select['rows'] = 100;
$client->createSelect($select);
$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>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment