Build the aggregation.

@param BucketInterface $bucket Term bucket.

@return array
347275
public function buildBucket(BucketInterface $bucket)
    {
        if ($bucket->getType() !== BucketInterface::TYPE_SIGNIFICANT_TERM) {
            throw new \InvalidArgumentException("Query builder : invalid aggregation type {$bucket->getType()}.");
        }
        $aggrepationParams = [
            'field'                 => $bucket->getField(),
            'size'                  => $bucket->getSize(),
            'min_doc_count'         => $bucket->getMinDocCount(),
            $bucket->getAlgorithm() => new \stdClass(),
        ];

        return ['significant_terms' => $aggrepationParams];
    }
727026
protected function buildKeysPath($type, $bucket)
    {
        if ($type === null) {
            return sprintf('/buckets/%s/keys', $bucket);
        }

        return sprintf('/types/%s/buckets/%s/keys', $type, $bucket);
    }
234381
public function toArray(): array
    {
        return array_filter([
            'aggregations' => array_map(function (Aggregation $aggregation) {
                return $aggregation->toArray();
            }, $this->getAggregations()),
            'total_elements' => $this->getTotalElements(),
        ]);
    }
252742
public function getUserAgentsForBucket()
    {
        if (empty($this->userAgents)) {
            $this->userAgents = $this->persistenceProvider->load($this->getPrefix(self::PREFIX_UA_BUCKET));
        }

        return $this->userAgents;
    }
569114
public function assemblePipeline() {
		$aggregate = [];
		
		// Conditions
		if (! empty($this->_conditions)) {
			$aggregate[] = [self::MONGO_PIPE_MATCH => $this->_conditions];
		}
		
		// Group
		if (! empty($this->_groupDefinition)) {
			$group = $this->_groupDefinition;
			
			$group[MongoCollection::DEFAULT_PRIMARY] = ($this->_groupBy === null)
				? null
				: '$' . $this->_groupBy;
			
			$aggregate[] = [self::MONGO_PIPE_GROUP => $group];
		}
		
		// Sort
		if (! empty($this->_sort)) {
			$aggregate[] = [self::MONGO_PIPE_SORT => $this->_sort];
		}
		
		// Offset
		if ($this->_offset !== null) {
			$aggregate[] = [self::MONGO_PIPE_OFFSET => $this->_offset];
		}
		
		// Limit
		if ($this->_limit !== null) {
			$aggregate[] = [self::MONGO_PIPE_LIMIT => $this->_limit];
		}
		
		return $aggregate;
	}
1177129
public function listBuckets()
    {
        $buckets = [];

        $response = $this->generateAuthenticatedClient([
            'accountId' => $this->accountId,
        ])->request('POST', '/b2_list_buckets');

        foreach ($response['buckets'] as $bucket) {
            $buckets[] = new Bucket($bucket['bucketId'], $bucket['bucketName'], $bucket['bucketType']);
        }

        return $buckets;
    }
731101
public function aggregate($aggregation = [])
    {
        if ($aggregation instanceof Closure) {
            // Store the callback
            $callback = $aggregation;

            // Create a new pipeline
            $aggregation = new Query\Aggregation();

            // Fire the callback
            $callback($aggregation);
        }

        if ($aggregation instanceof Query\Aggregation) {
            // Retrieve the pipeline
            $aggregation = $aggregation->getPipeline();
        }

        // Execute the aggregation.
        return $this->collection->aggregate($aggregation);
    }
399378
public function build()
    {
        $input = new BucketInput($this->namespace, $this->filters);
        $spec  = new Specification($input, $this->phases, $this->timeout);

        return new BucketMapReduce($spec);
    }
865090
public function toOptionArray()
    {
        return [
            ['value' => BucketInterface::SORT_ORDER_COUNT, 'label' => __('Result count')],
            ['value' => BucketInterface::SORT_ORDER_MANUAL, 'label' => __('Admin sort')],
            ['value' => BucketInterface::SORT_ORDER_TERM, 'label' => __('Name')],
            ['value' => BucketInterface::SORT_ORDER_RELEVANCE, 'label' => __('Relevance')],
        ];
    }
544043
public function buildBucket(BucketInterface $bucket)
    {
        if ($bucket->getType() !== BucketInterface::TYPE_TERM) {
            throw new \InvalidArgumentException("Query builder : invalid aggregation type {$bucket->getType()}.");
        }

        $aggregation = ['terms' => ['field' => $bucket->getField(), 'size' => $bucket->getSize()]];

        if (is_array($bucket->getSortOrder())) {
            $aggregation['terms']['order'] = $bucket->getSortOrder();
        } elseif (in_array($bucket->getSortOrder(), [$bucket::SORT_ORDER_COUNT, $bucket::SORT_ORDER_MANUAL])) {
            $aggregation['terms']['order'] = [$bucket::SORT_ORDER_COUNT => SortOrderInterface::SORT_DESC];
        } elseif ($bucket->getSortOrder() == $bucket::SORT_ORDER_TERM) {
            $aggregation['terms']['order'] = [$bucket::SORT_ORDER_TERM => SortOrderInterface::SORT_ASC];
        } elseif ($bucket->getSortOrder() == $bucket::SORT_ORDER_RELEVANCE && !$bucket->isNested()) {
            $aggregation['aggregations']['termRelevance'] = ['avg' => ['script' => $bucket::SORT_ORDER_RELEVANCE]];
            $aggregation['terms']['order'] = ['termRelevance' => SortOrderInterface::SORT_DESC];
        }

        return $aggregation;
    }
411592
protected function buildSelectFromAggregation(Aggregation $aggregation)
    {
        $tableAlias = $this->getAlias();
        $rawColumns = $aggregation->getFields();
        $newSelect = $this->getLookupBuilder()->buildJoin($this, $rawColumns);
        if (false === $newSelect) {
            if (empty($tableAlias) || '*' === $rawColumns) {
                $columns = $rawColumns;
            } else {
                $columns = $tableAlias.'.'.$rawColumns;
            }
        } else {
            list($alias, $joinColumn) = $newSelect;
            $columns = $alias.'.'.$joinColumn;
        }
        $fieldsSql = $this->buildColumns($columns);
        $aggregation->setFieldsSql($fieldsSql);

        return $this->getAdapter()->quoteSql($aggregation->toSQL());
    }
620346
public function bucket_get_objects( $options = array() ) {
	 	
	 	$result = null;
	 	if( ! is_array( $options ) ) {
		
			$this->errors[$this->error_count] = 'options not given as array';
			$this->error_count++;
		
		}
		try {
		
			$result = $this->bucket->objects( $options );
		
		}
		catch( \Exception $e ) {
	
			$result = $e;
			$this->errors[$this->error_count] = $e->getServiceException()->getMessage();
			$this->error_count++;
		
		}
		return $result;		
		
	 }
232664
private function createHeaders(BucketInterface $bucket, string $name, StreamInterface $stream): array
    {
        if (empty($mimetype = mimetype_from_filename($name))) {
            $mimetype = self::DEFAULT_MIMETYPE;
        };

        //Possible to add custom headers into the bucket
        $headers = $bucket->getOption('headers', []);

        if (!empty($maxAge = $bucket->getOption('maxAge', 0))) {
            //Shortcut
            $headers['Cache-control'] = 'max-age=' . $bucket->getOption('maxAge', 0) . ', public';
            $headers['Expires'] = gmdate(
                'D, d M Y H:i:s T',
                time() + $bucket->getOption('maxAge', 0)
            );
        }

        $stream->rewind();

        return $headers + [
                'Content-MD5'  => base64_encode(md5($stream->getContents(), true)),
                'Content-Type' => $mimetype
            ];
    }
149970
private function getAggregations(RequestInterface $request)
    {
        $aggregations = [];

        if ($request->getAggregation()) {
            $aggregations = $this->aggregationBuilder->buildAggregations($request->getAggregation());
        }

        return $aggregations;
    }
188003
public function buildIndex($bucketName, $indexNames)
    {
        $this->beginProfile($token = "    > build index $bucketName ...");

        $result = $this->db->buildIndex($bucketName, $indexNames);

        $this->endProfile($token);

        return $result;
    }
1235333
public function buildPipeline(PipelineInterface $pipeline)
    {
        if ($pipeline->getType() !== PipelineInterface::TYPE_BUCKET_SELECTOR) {
            throw new \InvalidArgumentException("Query builder : invalid aggregation type {$pipeline->getType()}.");
        }

        $aggParams = [
            'buckets_path'  => $pipeline->getBucketsPath(),
            'script'        => $pipeline->getScript(),
            'gap_policy'    => $pipeline->getGapPolicy(),
        ];

        return ['bucket_selector' => $aggParams];
    }
1149444
protected function buildBucket($bucketName)
	{
		if (!$this->getS3Client()->doesBucketExist($bucketName, true)) {
			$this->getS3Client()->createBucket(['ACL' => $this->attachedFile->ACL, 'Bucket' => $bucketName, 'LocationConstraint' => $this->attachedFile->region]);
		}

		$this->bucketExists = true;
	}