-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQueryString.php
More file actions
156 lines (123 loc) · 3.81 KB
/
Copy pathQueryString.php
File metadata and controls
156 lines (123 loc) · 3.81 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
declare(strict_types = 1);
namespace Spameri\ElasticQuery\Query;
/**
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
*/
class QueryString implements \Spameri\ElasticQuery\Query\LeafQueryInterface
{
/**
* @param array<int, string> $fields
*/
public function __construct(
private string $query,
private array $fields = [],
private string|null $defaultField = null,
private string|null $defaultOperator = null,
private string|null $analyzer = null,
private bool|null $allowLeadingWildcard = null,
private float $boost = 1.0,
private bool|null $analyzeWildcard = null,
private bool|null $autoGenerateSynonymsPhraseQuery = null,
private bool|null $enablePositionIncrements = null,
private \Spameri\ElasticQuery\Query\Match\Fuzziness|null $fuzziness = null,
private int|null $fuzzyMaxExpansions = null,
private int|null $fuzzyPrefixLength = null,
private bool|null $fuzzyTranspositions = null,
private bool|null $lenient = null,
private int|null $maxDeterminizedStates = null,
private int|string|null $minimumShouldMatch = null,
private string|null $quoteAnalyzer = null,
private int|null $phraseSlop = null,
private string|null $quoteFieldSuffix = null,
private string|null $rewrite = null,
private string|null $timeZone = null,
private string|null $type = null,
private float|null $tieBreaker = null,
)
{
}
public function key(): string
{
return 'query_string_' . $this->query;
}
/**
* @return array<string, array<string, mixed>>
*/
public function toArray(): array
{
$body = [
'query' => $this->query,
'boost' => $this->boost,
];
if ($this->fields !== []) {
$body['fields'] = $this->fields;
}
if ($this->defaultField !== null) {
$body['default_field'] = $this->defaultField;
}
if ($this->defaultOperator !== null) {
$body['default_operator'] = $this->defaultOperator;
}
if ($this->analyzer !== null) {
$body['analyzer'] = $this->analyzer;
}
if ($this->allowLeadingWildcard !== null) {
$body['allow_leading_wildcard'] = $this->allowLeadingWildcard;
}
if ($this->analyzeWildcard !== null) {
$body['analyze_wildcard'] = $this->analyzeWildcard;
}
if ($this->autoGenerateSynonymsPhraseQuery !== null) {
$body['auto_generate_synonyms_phrase_query'] = $this->autoGenerateSynonymsPhraseQuery;
}
if ($this->enablePositionIncrements !== null) {
$body['enable_position_increments'] = $this->enablePositionIncrements;
}
if ($this->fuzziness !== null) {
$body['fuzziness'] = $this->fuzziness->__toString();
}
if ($this->fuzzyMaxExpansions !== null) {
$body['fuzzy_max_expansions'] = $this->fuzzyMaxExpansions;
}
if ($this->fuzzyPrefixLength !== null) {
$body['fuzzy_prefix_length'] = $this->fuzzyPrefixLength;
}
if ($this->fuzzyTranspositions !== null) {
$body['fuzzy_transpositions'] = $this->fuzzyTranspositions;
}
if ($this->lenient !== null) {
$body['lenient'] = $this->lenient;
}
if ($this->maxDeterminizedStates !== null) {
$body['max_determinized_states'] = $this->maxDeterminizedStates;
}
if ($this->minimumShouldMatch !== null) {
$body['minimum_should_match'] = $this->minimumShouldMatch;
}
if ($this->quoteAnalyzer !== null) {
$body['quote_analyzer'] = $this->quoteAnalyzer;
}
if ($this->phraseSlop !== null) {
$body['phrase_slop'] = $this->phraseSlop;
}
if ($this->quoteFieldSuffix !== null) {
$body['quote_field_suffix'] = $this->quoteFieldSuffix;
}
if ($this->rewrite !== null) {
$body['rewrite'] = $this->rewrite;
}
if ($this->timeZone !== null) {
$body['time_zone'] = $this->timeZone;
}
if ($this->type !== null) {
$body['type'] = $this->type;
}
if ($this->tieBreaker !== null) {
$body['tie_breaker'] = $this->tieBreaker;
}
return [
'query_string' => $body,
];
}
}