Skip to content

Commit

Permalink
[Term Recommender] #ESP-306 Add min_doc_count in term aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreGauthier committed Nov 26, 2021
1 parent 0302b1c commit 4b0b7c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public function buildBucket(BucketInterface $bucket)
if (!empty($bucket->getExclude())) {
$aggregation['terms']['exclude'] = $bucket->getExclude();
}
if ($bucket->getMinDocCount() !== null) {
$aggregation['terms']['min_doc_count'] = $bucket->getMinDocCount();
}

return $aggregation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class Term extends AbstractBucket
*/
private $exclude;

/**
* @var int
*/
private $minDocCount;

/**
* Constructor.
*
Expand All @@ -65,6 +70,7 @@ class Term extends AbstractBucket
* @param string $sortOrder Bucket sort order.
* @param array $include Include bucket filter.
* @param array $exclude Exclude bucket filter.
* @param int $minDocCount Min doc count bucket filter.
*/
public function __construct(
$name,
Expand All @@ -78,14 +84,16 @@ public function __construct(
$size = 0,
$sortOrder = BucketInterface::SORT_ORDER_COUNT,
$include = [],
$exclude = []
$exclude = [],
$minDocCount = null
) {
parent::__construct($name, $field, $metrics, $childBuckets, $pipelines, $nestedPath, $filter, $nestedFilter);

$this->size = $size > 0 && $size < self::MAX_BUCKET_SIZE ? $size : self::MAX_BUCKET_SIZE;
$this->sortOrder = $sortOrder;
$this->include = $include;
$this->exclude = $exclude;
$this->minDocCount = $minDocCount;
}

/**
Expand Down Expand Up @@ -135,4 +143,14 @@ public function getExclude()
{
return $this->exclude;
}

/**
* Bucket min doc count filter.
*
* @return int
*/
public function getMinDocCount()
{
return $this->minDocCount;
}
}

0 comments on commit 4b0b7c1

Please sign in to comment.