-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFunctionScore.php
More file actions
93 lines (71 loc) · 2.12 KB
/
Copy pathFunctionScore.php
File metadata and controls
93 lines (71 loc) · 2.12 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
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
declare(strict_types = 1);
namespace Spameri\ElasticQuery;
class FunctionScore
{
public const SCORE_MODE_MULTIPLY = 'multiply';
public const SCORE_MODE_SUM = 'sum';
public const SCORE_MODE_AVG = 'avg';
public const SCORE_MODE_FIRST = 'first';
public const SCORE_MODE_MAX = 'max';
public const SCORE_MODE_MIN = 'min';
public const BOOST_MODE_MULTIPLY = 'multiply';
public const BOOST_MODE_REPLACE = 'replace';
public const BOOST_MODE_SUM = 'sum';
public const BOOST_MODE_AVG = 'avg';
public const BOOST_MODE_MAX = 'max';
public const BOOST_MODE_MIN = 'min';
private \Spameri\ElasticQuery\FunctionScore\FunctionScoreCollection $function;
public function __construct(
\Spameri\ElasticQuery\FunctionScore\FunctionScoreCollection|null $function = null,
private string|null $scoreMode = null,
private string|null $boostMode = null,
private float|null $boost = null,
private float|null $maxBoost = null,
private float|null $minScore = null,
)
{
$this->function = $function ?? new \Spameri\ElasticQuery\FunctionScore\FunctionScoreCollection();
}
public function function(): \Spameri\ElasticQuery\FunctionScore\FunctionScoreCollection
{
return $this->function;
}
public function scoreMode(): string|null
{
return $this->scoreMode;
}
/**
* @param array<string, mixed> $queryPart
* @return array<string, array<string, mixed>>
*/
public function toArray(array $queryPart): array
{
$functions = [];
foreach ($this->function() as $function) {
$functions[] = $function->toArray();
}
$array = [
'function_score' => [
'query' => $queryPart,
'functions' => $functions,
],
];
if ($this->scoreMode !== null) {
$array['function_score']['score_mode'] = $this->scoreMode;
}
if ($this->boostMode !== null) {
$array['function_score']['boost_mode'] = $this->boostMode;
}
if ($this->boost !== null) {
$array['function_score']['boost'] = $this->boost;
}
if ($this->maxBoost !== null) {
$array['function_score']['max_boost'] = $this->maxBoost;
}
if ($this->minScore !== null) {
$array['function_score']['min_score'] = $this->minScore;
}
return $array;
}
}