1<?php
2
3namespace Elastica\Aggregation;
4
5/**
6 * Class AbstractTermsAggregation.
7 */
8abstract class AbstractTermsAggregation extends AbstractSimpleAggregation
9{
10    /**
11     * Set the minimum number of documents in which a term must appear in order to be returned in a bucket.
12     *
13     * @param int $count
14     *
15     * @return $this
16     */
17    public function setMinimumDocumentCount(int $count): self
18    {
19        return $this->setParam('min_doc_count', $count);
20    }
21
22    /**
23     * Filter documents to include based on a regular expression.
24     *
25     * @param string $pattern a regular expression
26     * @param string $flags   Java Pattern flags
27     *
28     * @return $this
29     */
30    public function setInclude(string $pattern, string $flags = null): self
31    {
32        if (null === $flags) {
33            return $this->setParam('include', $pattern);
34        }
35
36        return $this->setParam('include', [
37            'pattern' => $pattern,
38            'flags' => $flags,
39        ]);
40    }
41
42    /**
43     * Filter documents to exclude based on a regular expression.
44     *
45     * @param string $pattern a regular expression
46     * @param string $flags   Java Pattern flags
47     *
48     * @return $this
49     */
50    public function setExclude(string $pattern, string $flags = null): self
51    {
52        if (null === $flags) {
53            return $this->setParam('exclude', $pattern);
54        }
55
56        return $this->setParam('exclude', [
57            'pattern' => $pattern,
58            'flags' => $flags,
59        ]);
60    }
61
62    /**
63     * Sets the amount of terms to be returned.
64     *
65     * @param int $size the amount of terms to be returned
66     *
67     * @return $this
68     */
69    public function setSize(int $size): self
70    {
71        return $this->setParam('size', $size);
72    }
73
74    /**
75     * Sets how many terms the coordinating node will request from each shard.
76     *
77     * @param int $shardSize the amount of terms to be returned
78     *
79     * @return $this
80     */
81    public function setShardSize(int $shardSize): self
82    {
83        return $this->setParam('shard_size', $shardSize);
84    }
85
86    /**
87     * Instruct Elasticsearch to use direct field data or ordinals of the field values to execute this aggregation.
88     * The execution hint will be ignored if it is not applicable.
89     *
90     * @param string $hint map or ordinals
91     *
92     * @return $this
93     */
94    public function setExecutionHint(string $hint): self
95    {
96        return $this->setParam('execution_hint', $hint);
97    }
98}
99