-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFunctionScore.php
More file actions
62 lines (45 loc) · 1.29 KB
/
FunctionScore.php
File metadata and controls
62 lines (45 loc) · 1.29 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
<?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';
private \Spameri\ElasticQuery\FunctionScore\FunctionScoreCollection $function;
private ?string $scoreMode;
public function __construct(
?\Spameri\ElasticQuery\FunctionScore\FunctionScoreCollection $function = NULL,
?string $scoreMode = NULL
) {
$this->function = $function ?? new \Spameri\ElasticQuery\FunctionScore\FunctionScoreCollection();
$this->scoreMode = $scoreMode;
}
public function function(): \Spameri\ElasticQuery\FunctionScore\FunctionScoreCollection
{
return $this->function;
}
public function scoreMode(): ?string
{
return $this->scoreMode;
}
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;
}
return $array;
}
}