-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCategorizeText.php
More file actions
80 lines (61 loc) · 1.78 KB
/
Copy pathCategorizeText.php
File metadata and controls
80 lines (61 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types = 1);
namespace Spameri\ElasticQuery\Aggregation;
/**
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-categorize-text-aggregation.html
*/
class CategorizeText implements LeafAggregationInterface
{
/**
* @param array<int, string>|null $categorizationFilters
*/
public function __construct(
private string $field,
private int|null $maxUniqueTokens = null,
private int|null $maxMatchedTokens = null,
private float|null $similarityThreshold = null,
private array|null $categorizationFilters = null,
private int|null $shardSize = null,
private int|null $size = null,
private int|null $minDocCount = null,
private int|null $shardMinDocCount = null,
)
{
}
public function key(): string
{
return 'categorize_text_' . $this->field;
}
/**
* @return array<string, array<string, mixed>>
*/
public function toArray(): array
{
$array = ['field' => $this->field];
if ($this->maxUniqueTokens !== null) {
$array['max_unique_tokens'] = $this->maxUniqueTokens;
}
if ($this->maxMatchedTokens !== null) {
$array['max_matched_tokens'] = $this->maxMatchedTokens;
}
if ($this->similarityThreshold !== null) {
$array['similarity_threshold'] = $this->similarityThreshold;
}
if ($this->categorizationFilters !== null) {
$array['categorization_filters'] = $this->categorizationFilters;
}
if ($this->shardSize !== null) {
$array['shard_size'] = $this->shardSize;
}
if ($this->size !== null) {
$array['size'] = $this->size;
}
if ($this->minDocCount !== null) {
$array['min_doc_count'] = $this->minDocCount;
}
if ($this->shardMinDocCount !== null) {
$array['shard_min_doc_count'] = $this->shardMinDocCount;
}
return ['categorize_text' => $array];
}
}