|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace olvlvl\ElasticsearchDSL\Query; |
|
4
|
|
|
|
|
5
|
|
|
use olvlvl\ElasticsearchDSL\Helpers; |
|
6
|
|
|
use olvlvl\ElasticsearchDSL\Query\Text\MatchAllQuery; |
|
7
|
|
|
use olvlvl\ElasticsearchDSL\Query\Text\MatchNoneQuery; |
|
8
|
|
|
use olvlvl\ElasticsearchDSL\Query\Text\MatchPhrasePrefixQuery; |
|
9
|
|
|
use olvlvl\ElasticsearchDSL\Query\Text\MatchPhraseQuery; |
|
10
|
|
|
use olvlvl\ElasticsearchDSL\Query\Text\MatchQuery; |
|
11
|
|
|
use olvlvl\ElasticsearchDSL\Query\Text\MultiMatchQuery; |
|
12
|
|
|
|
|
13
|
|
|
trait TextQueries |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var MatchAllQuery[] |
|
17
|
|
|
*/ |
|
18
|
|
|
private $match_all = []; |
|
19
|
|
|
|
|
20
|
|
|
public function match_all(callable $config = null) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->match_all[] = $q = new MatchAllQuery(); |
|
23
|
|
|
|
|
24
|
|
|
if ($config) { |
|
25
|
|
|
$config($q); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
return $this; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var MatchNoneQuery[] |
|
33
|
|
|
*/ |
|
34
|
|
|
private $match_none = []; |
|
35
|
|
|
|
|
36
|
|
|
public function match_none() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->match_none[] = new MatchNoneQuery(); |
|
39
|
|
|
|
|
40
|
|
|
return $this; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var MatchQuery[] |
|
45
|
|
|
*/ |
|
46
|
|
|
private $match = []; |
|
47
|
|
|
|
|
48
|
|
|
public function match(string $field, string $query, callable $config = null) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->match[] = $q = new MatchQuery($field, $query); |
|
51
|
|
|
|
|
52
|
|
|
if ($config) { |
|
53
|
|
|
$config($q); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var MatchPhraseQuery[] |
|
61
|
|
|
*/ |
|
62
|
|
|
private $match_phrase = []; |
|
63
|
|
|
|
|
64
|
|
|
public function match_phrase(string $field, string $query, callable $config = null) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->match_phrase[] = $q = new MatchPhraseQuery($field, $query); |
|
67
|
|
|
|
|
68
|
|
|
if ($config) { |
|
69
|
|
|
$config($q); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @var MatchPhrasePrefixQuery[] |
|
77
|
|
|
*/ |
|
78
|
|
|
private $match_phrase_prefix = []; |
|
79
|
|
|
|
|
80
|
|
|
public function match_phrase_prefix(string $field, string $query, callable $config = null) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->match_phrase_prefix[] = $q = new MatchPhrasePrefixQuery($field, $query); |
|
83
|
|
|
|
|
84
|
|
|
if ($config) { |
|
85
|
|
|
$config($q); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @var MultiMatchQuery[] |
|
93
|
|
|
*/ |
|
94
|
|
|
private $multi_match = []; |
|
95
|
|
|
|
|
96
|
|
|
public function multi_match(array $fields, string $query, callable $config = null) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->multi_match[] = $q = new MultiMatchQuery($fields, $query); |
|
99
|
|
|
|
|
100
|
|
|
if ($config) { |
|
101
|
|
|
$config($q); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
protected function jsonSerializeTextQueries(): array |
|
108
|
|
|
{ |
|
109
|
|
|
return Helpers::filter_merge( |
|
110
|
|
|
$this->match_all, |
|
111
|
|
|
$this->match_none, |
|
112
|
|
|
$this->match, |
|
113
|
|
|
$this->match_phrase, |
|
114
|
|
|
$this->match_phrase_prefix, |
|
115
|
|
|
$this->multi_match |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|