mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
More complete faceting example for docs.
This commit is contained in:
parent
034171270f
commit
234eac8308
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user