public function __construct(Escaper $escaper, array $response) { $this->escaper = $escaper; if (!isset($response['aggregations'])) { return; } foreach ($response['aggregations'] as $name => $aggregation) { $aggregation = AggregationHelper::unwrapPrivateFieldAggregation($aggregation); if (!isset($aggregation['buckets'])) { $this->throwAggregationResponseError(); } $values = $this->buildBucketsValues($name, $aggregation['buckets']); if ($values) { $this->facets[] = array('name' => $name, 'values' => $values); } } }
public function testUnwrappingOnNotWrappedAggregation() { $agg = ['buckets' => [['key' => 'foo', 'doc_count' => 1]]]; $unwrapped = AggregationHelper::unwrapPrivateFieldAggregation($agg); $this->assertEquals($agg, $unwrapped); }
private function getAggregationQueryParams(SearchEngineOptions $options) { $aggs = []; // We always want a collection facet right now $collection_facet_agg = array(); $collection_facet_agg['terms']['field'] = 'collection_name'; $aggs['Collection_Name'] = $collection_facet_agg; // We always want a base facet right now $base_facet_agg = array(); $base_facet_agg['terms']['field'] = 'databox_name'; $aggs['Base_Name'] = $base_facet_agg; // We always want a type facet right now $base_facet_agg = array(); $base_facet_agg['terms']['field'] = 'type'; $aggs['Type_Name'] = $base_facet_agg; $structure = $this->context_factory->getLimitedStructure($options); foreach ($structure->getFacetFields() as $name => $field) { // 2015-05-26 (mdarse) Removed databox filtering. // It was already done by the ACL filter in the query scope, so no // document that shouldn't be displayed can go this far. $agg = []; $agg['terms']['field'] = $field->getIndexField(true); $agg['terms']['size'] = $field->getFacetValuesLimit(); $aggs[$name] = AggregationHelper::wrapPrivateFieldAggregation($field, $agg); } return $aggs; }