-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRegexp.phpt
More file actions
94 lines (67 loc) · 2.02 KB
/
Copy pathRegexp.phpt
File metadata and controls
94 lines (67 loc) · 2.02 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
<?php declare(strict_types = 1);
namespace SpameriTests\ElasticQuery\Query;
require_once __DIR__ . '/../../bootstrap.php';
class Regexp extends \SpameriTests\ElasticQuery\AbstractElasticTestCase
{
protected const INDEX = 'spameri_test_query_regexp';
protected function mapping(): array|null
{
return ['mappings' => ['properties' => ['user' => ['type' => 'keyword']]]];
}
public function testToArray(): void
{
$regexp = new \Spameri\ElasticQuery\Query\Regexp('user', 'k.*y');
\Tester\Assert::same('k.*y', $regexp->toArray()['regexp']['user']['value']);
}
public function testRewriteOption(): void
{
$regexp = new \Spameri\ElasticQuery\Query\Regexp(
field: 'user',
query: 'k.*',
rewrite: 'constant_score',
);
\Tester\Assert::same('constant_score', $regexp->toArray()['regexp']['user']['rewrite']);
}
public function testKey(): void
{
$regexp = new \Spameri\ElasticQuery\Query\Regexp('user', 'k.*');
\Tester\Assert::same('regexp_user_k.*', $regexp->key());
}
public function testCreate(): void
{
$this->indexDocument(['user' => 'kimchy']);
$query = new \Spameri\ElasticQuery\ElasticQuery(
new \Spameri\ElasticQuery\Query\QueryCollection(
null,
new \Spameri\ElasticQuery\Query\MustCollection(
new \Spameri\ElasticQuery\Query\Regexp('user', 'k.*'),
),
),
);
$result = $this->search($query);
\Tester\Assert::same(1, $result->stats()->total());
}
public function testCreateWithAllOptions(): void
{
$this->indexDocument(['user' => 'kimchy']);
$query = new \Spameri\ElasticQuery\ElasticQuery(
new \Spameri\ElasticQuery\Query\QueryCollection(
null,
new \Spameri\ElasticQuery\Query\MustCollection(
new \Spameri\ElasticQuery\Query\Regexp(
field: 'user',
query: 'k.*',
boost: 2.0,
flags: 'ALL',
caseInsensitive: false,
maxDeterminizedStates: 10000,
rewrite: 'constant_score',
),
),
),
);
$result = $this->search($query);
\Tester\Assert::same(1, $result->stats()->total());
}
}
(new Regexp())->run();