From 234eac8308fde757d793d0eccf5e6e4acb393e52 Mon Sep 17 00:00:00 2001 From: Darren Inwood Date: Mon, 9 May 2016 16:19:01 +1200 Subject: [PATCH] More complete faceting example for docs. --- docs/en/Solr.md | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/docs/en/Solr.md b/docs/en/Solr.md index 6af8c2f..60d9a2e 100644 --- a/docs/en/Solr.md +++ b/docs/en/Solr.md @@ -363,17 +363,26 @@ to the page. * results pages. * @param $response The solr-php-client response object. */ - function updateSearchResults($results, $response) { - $facetCounts = array(); - if (isset($response->facet_counts)) { - foreach ($response->facet_counts as $facet => $count) { - $facetCounts[] = new ArrayData(array( - 'Name' => $facet, - 'Count' => $count, - )); - } + public function updateSearchResults($results, $response) + { + if (!isset($response->facet_counts) || !isset($response->facet_counts->facet_fields)) { + return; } - $results->setField('FacetCounts', new ArrayList($facetCounts)); + $facetCounts = ArrayList::create(array()); + 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', $facetCounts); } }