More complete faceting example for docs.

This commit is contained in:
Darren Inwood 2016-05-09 16:19:01 +12:00
parent 034171270f
commit 234eac8308

View File

@ -363,17 +363,26 @@ to the page.
* results pages. * results pages.
* @param $response The solr-php-client response object. * @param $response The solr-php-client response object.
*/ */
function updateSearchResults($results, $response) { public function updateSearchResults($results, $response)
$facetCounts = array(); {
if (isset($response->facet_counts)) { if (!isset($response->facet_counts) || !isset($response->facet_counts->facet_fields)) {
foreach ($response->facet_counts as $facet => $count) { return;
$facetCounts[] = new ArrayData(array( }
'Name' => $facet, $facetCounts = ArrayList::create(array());
'Count' => $count, foreach($response->facet_counts->facet_fields as $name => $facets) {
$facetDetails = ArrayData::create(array(
'Name' => $name,
'Facets' => ArrayList::create(array()),
)); ));
foreach($facets as $facetName => $facetCount) {
$facetDetails->Facets->push(ArrayData::create(array(
'Name' => $facetName,
'Count' => $facetCount,
)));
} }
$facetCounts->push($facetDetails);
} }
$results->setField('FacetCounts', new ArrayList($facetCounts)); $results->setField('FacetCounts', $facetCounts);
} }
} }