/** * Test for reverse nested terms aggregation. * * @param AbstractAggregation $aggregation * @param AbstractAggregation $reverseAggregation * @param array $expectedResult * @param array $mapping * * @dataProvider getReverseNestedAggregationData */ public function testReverseNestedAggregation($aggregation, $reverseAggregation, $expectedResult, $mapping) { $repository = $this->getManager('default', true, $mapping)->getRepository('AcmeTestBundle:Product'); $revereNestedAggregation = new ReverseNestedAggregation('test_reverse_nested_agg'); $revereNestedAggregation->addAggregation($reverseAggregation); $aggregation->addAggregation($revereNestedAggregation); $nestedAggregation = new NestedAggregation('test_nested_agg'); $nestedAggregation->setPath('sub_products'); $nestedAggregation->addAggregation($aggregation); $search = $repository->createSearch()->addAggregation($nestedAggregation); $results = $repository->execute($search, Repository::RESULTS_RAW); $this->assertArrayHasKey('aggregations', $results); $this->assertArraySubset($expectedResult, $results['aggregations']['agg_test_nested_agg']); }
/** * Gets the definition for the projection. * * @return array */ protected function getDefinition() { $definition = parent::getDefinition(); if (!is_array($definition)) { $definition = []; } return $definition; }
/** * {@inheritdoc} */ public function toArray() { $array = parent::toArray(); // ensure we have an object for the reverse_nested key. // if we don't have a path, then this would otherwise get encoded as an empty array, which is invalid. $array['reverse_nested'] = (object) $array['reverse_nested']; return $array; }
/** * {@inheritdoc} */ public function toArray() { $array = parent::toArray(); $baseName = $this->_getBaseName(); if (isset($array[$baseName]['script']) && is_array($array[$baseName]['script'])) { $script = $array[$baseName]['script']; unset($array[$baseName]['script']); $array[$baseName] = array_merge($array[$baseName], $script); } return $array; }
/** * @param string $name the name if this aggregation * @param string|null $initScript Executed prior to any collection of documents * @param string|null $mapScript Executed once per document collected * @param string|null $combineScript Executed once on each shard after document collection is complete * @param string|null $reduceScript Executed once on the coordinating node after all shards have returned their results */ public function __construct($name, $initScript = null, $mapScript = null, $combineScript = null, $reduceScript = null) { parent::__construct($name); if ($initScript) { $this->setInitScript($initScript); } if ($mapScript) { $this->setMapScript($mapScript); } if ($combineScript) { $this->setCombineScript($combineScript); } if ($reduceScript) { $this->setReduceScript($reduceScript); } }
/** * @param string $name the name of this aggregation * @param string $field the field on which to perform this aggregation */ public function __construct($name, $field) { parent::__construct($name); $this->setField($field); }
/** * @param string $name the name of this aggregation * @param string $path the nested path for this aggregation */ public function __construct($name, $path) { parent::__construct($name); $this->setPath($path); }
public function __construct($propertyName) { parent::__construct('SUM', $propertyName); }