Accessing faceting results with solr php client

45 views
Skip to first unread message

Sami R al-Subhi

unread,
Dec 19, 2017, 8:39:37 AM12/19/17
to PHP Solr Client
you are my last resort. I got the the connection working with solr. I am able to access the docs data using the code below but I do not know how to access the facet_count data. I searched the net and I tried some  codes like `$response->facet_count` but I could not find a solution. Can you please help!



require_once( 'solr-php-client/Apache/Solr/Service.php' );


$solr = new Apache_Solr_Service( 'localhost', '8983', '/solr/products' );

if ( ! $solr->ping() ) {
   echo 'Solr service not responding.';
   exit;
}


$offset = 0;
$limit = 10;


$queries = array(
  'name:iphone'
);
$additionalParameters = array(
  'facet' => 'true',
  'facet.field' => array(
     'category'
  )
);

foreach ( $queries as $query ) {
$response = $solr->search( $query, $offset, $limit );

if ( $response->getHttpStatus() == 200 ) {

  if ( $response->response->numFound > 0 ) {
    echo "$query <br />";

    foreach ( $response->response->docs as $doc ) {
      echo "$doc->id $doc->name <br />";
    }

    echo '<br />';
  }else{
    echo "zero results";
  }
}
else {
  echo $response->getHttpStatusMessage();
  }
 }
Reply all
Reply to author
Forward
0 new messages