-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTermSet.phpt
More file actions
99 lines (77 loc) · 2.17 KB
/
Copy pathTermSet.phpt
File metadata and controls
99 lines (77 loc) · 2.17 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
94
95
96
97
98
99
<?php declare(strict_types = 1);
namespace SpameriTests\ElasticQuery\Query;
require_once __DIR__ . '/../../bootstrap.php';
class TermSet extends \SpameriTests\ElasticQuery\AbstractElasticTestCase
{
protected const INDEX = 'spameri_test_query_term_set';
protected function mapping(): array|null
{
return [
'mappings' => [
'properties' => [
'programming_languages' => ['type' => 'keyword'],
'required_matches' => ['type' => 'long'],
],
],
];
}
public function testToArray(): void
{
$termSet = new \Spameri\ElasticQuery\Query\TermSet(
field: 'programming_languages',
terms: ['c++', 'java', 'php'],
minimumShouldMatchField: 'required_matches',
boost: 2.0,
);
$array = $termSet->toArray();
\Tester\Assert::same(
['c++', 'java', 'php'],
$array['terms_set']['programming_languages']['terms'],
);
\Tester\Assert::same(2.0, $array['terms_set']['programming_languages']['boost']);
\Tester\Assert::same(
'required_matches',
$array['terms_set']['programming_languages']['minimum_should_match_field'],
);
}
public function testRequiresTerms(): void
{
\Tester\Assert::exception(
static function (): void {
new \Spameri\ElasticQuery\Query\TermSet('f', [], 'm');
},
\Spameri\ElasticQuery\Exception\InvalidArgumentException::class,
);
}
public function testRequiresMinimumShouldMatch(): void
{
\Tester\Assert::exception(
static function (): void {
new \Spameri\ElasticQuery\Query\TermSet('f', ['a']);
},
\Spameri\ElasticQuery\Exception\InvalidArgumentException::class,
);
}
public function testCreate(): void
{
$this->indexDocument([
'programming_languages' => ['c++', 'java', 'php'],
'required_matches' => 2,
]);
$query = new \Spameri\ElasticQuery\ElasticQuery(
new \Spameri\ElasticQuery\Query\QueryCollection(
null,
new \Spameri\ElasticQuery\Query\MustCollection(
new \Spameri\ElasticQuery\Query\TermSet(
field: 'programming_languages',
terms: ['c++', 'java', 'php'],
minimumShouldMatchField: 'required_matches',
),
),
),
);
$result = $this->search($query);
\Tester\Assert::same(1, $result->stats()->total());
}
}
(new TermSet())->run();