1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\FluentAQL\AQL; |
6
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\Expression; |
8
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression; |
9
|
|
|
use LaravelFreelancerNL\FluentAQL\QueryBuilder; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Geo AQL functions. |
13
|
|
|
* |
14
|
|
|
* @see https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html |
15
|
|
|
*/ |
16
|
|
|
trait HasArangoSearchFunctions |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* set the analyzer for the given search expression |
20
|
|
|
* |
21
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html#analyzer |
22
|
|
|
*/ |
23
|
8 |
|
public function analyzer(): FunctionExpression |
24
|
|
|
{ |
25
|
8 |
|
$arguments = func_get_args(); |
26
|
|
|
|
27
|
|
|
/** @var string $analyzer */ |
28
|
8 |
|
$analyzer = array_pop($arguments); |
29
|
|
|
|
30
|
8 |
|
$predicates = $arguments; |
31
|
8 |
|
if (! is_array($predicates[0])) { |
32
|
7 |
|
$predicates = [[ |
33
|
7 |
|
...$predicates |
34
|
|
|
]]; |
35
|
|
|
} |
36
|
8 |
|
$preppedArguments = [ |
37
|
8 |
|
'predicates' => $predicates, |
38
|
8 |
|
'analyzer' => $analyzer |
39
|
|
|
]; |
40
|
8 |
|
return new FunctionExpression('ANALYZER', $preppedArguments); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Override the boost value of the search expression |
45
|
|
|
* |
46
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html#boost |
47
|
|
|
*/ |
48
|
2 |
|
public function boost(): FunctionExpression |
49
|
|
|
{ |
50
|
2 |
|
$arguments = func_get_args(); |
51
|
|
|
|
52
|
|
|
/** @var int|float $boost */ |
53
|
2 |
|
$boost = array_pop($arguments); |
54
|
|
|
|
55
|
2 |
|
$predicates = $arguments; |
56
|
2 |
|
if (! is_array($predicates[0])) { |
57
|
1 |
|
$predicates = [[ |
58
|
1 |
|
...$predicates |
59
|
|
|
]]; |
60
|
|
|
} |
61
|
2 |
|
$preppedArguments = [ |
62
|
2 |
|
'predicates' => $predicates, |
63
|
2 |
|
'boost' => $boost |
64
|
|
|
]; |
65
|
2 |
|
return new FunctionExpression('BOOST', $preppedArguments); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Sorts documents using the Best Matching 25 algorithm (Okapi BM25). |
70
|
|
|
* |
71
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html#bm25 |
72
|
|
|
*/ |
73
|
3 |
|
public function bm25( |
74
|
|
|
string|Expression $doc, |
75
|
|
|
int|float|Expression|QueryBuilder $k = null, |
76
|
|
|
int|float|Expression|QueryBuilder $b = null |
77
|
|
|
): FunctionExpression { |
78
|
3 |
|
$arguments = [ |
79
|
3 |
|
$doc, |
80
|
3 |
|
$k, |
81
|
3 |
|
$b |
82
|
|
|
]; |
83
|
3 |
|
$arguments = array_filter($arguments); |
84
|
|
|
|
85
|
3 |
|
return new FunctionExpression('BM25', $arguments); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Sorts documents using the term frequency–inverse document frequency algorithm (TF-IDF). |
90
|
|
|
* |
91
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html#tfidf |
92
|
|
|
*/ |
93
|
2 |
|
public function tfidf( |
94
|
|
|
string|Expression $doc, |
95
|
|
|
bool|Expression|QueryBuilder $normalize = null |
96
|
|
|
): FunctionExpression { |
97
|
2 |
|
$arguments = [ |
98
|
2 |
|
$doc, |
99
|
|
|
]; |
100
|
2 |
|
if (isset($normalize)) { |
101
|
1 |
|
$arguments[] = $normalize; |
102
|
|
|
} |
103
|
|
|
|
104
|
2 |
|
return new FunctionExpression('TFIDF', $arguments); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Match documents where the attribute at path is present and is of the specified data type. |
109
|
|
|
* |
110
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html#exists |
111
|
|
|
* |
112
|
|
|
* @param Expression|QueryBuilder|string $path |
113
|
|
|
* @param Expression|QueryBuilder|null|string $type |
114
|
|
|
* |
115
|
|
|
* @return FunctionExpression |
116
|
|
|
*/ |
117
|
2 |
|
public function exists( |
118
|
|
|
Expression|QueryBuilder|string $path, |
119
|
|
|
Expression|null|string|QueryBuilder $type = null |
|
|
|
|
120
|
|
|
): FunctionExpression { |
121
|
2 |
|
$arguments = [ |
122
|
2 |
|
$path, |
123
|
2 |
|
$type, |
124
|
|
|
]; |
125
|
2 |
|
$arguments = array_filter($arguments); |
126
|
|
|
|
127
|
2 |
|
return new FunctionExpression('EXISTS', $arguments); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Match documents where the attribute at path is present and is of the specified data type. |
132
|
|
|
* |
133
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html#in_range |
134
|
|
|
* |
135
|
|
|
* @param string|Expression $path |
136
|
|
|
* @param int|float|string|Expression|QueryBuilder $low |
137
|
|
|
* @param int|float|string|Expression|QueryBuilder $high |
138
|
|
|
* @param bool|Expression|QueryBuilder|null $includeLow |
139
|
|
|
* @param bool|Expression|QueryBuilder|null $includeHigh |
140
|
|
|
* @return FunctionExpression |
141
|
|
|
*/ |
142
|
2 |
|
public function inRange( |
143
|
|
|
string|Expression $path, |
144
|
|
|
int|float|string|Expression|QueryBuilder $low, |
145
|
|
|
int|float|string|Expression|QueryBuilder $high, |
146
|
|
|
bool|Expression|QueryBuilder $includeLow = null, |
147
|
|
|
bool|Expression|QueryBuilder $includeHigh = null |
148
|
|
|
): FunctionExpression { |
149
|
2 |
|
$arguments = [ |
150
|
2 |
|
"path" => $path, |
151
|
2 |
|
"low" => $low, |
152
|
2 |
|
"high" => $high, |
153
|
2 |
|
"includeLow" => $includeLow, |
154
|
2 |
|
"includeHigh" => $includeHigh |
155
|
|
|
]; |
156
|
2 |
|
$arguments = $this->unsetNullValues($arguments); |
|
|
|
|
157
|
|
|
|
158
|
2 |
|
return new FunctionExpression('IN_RANGE', $arguments); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Match documents with a Damerau-Levenshtein distance lower than or equal to |
163
|
|
|
* the distance between the stored attribute value and target. |
164
|
|
|
* |
165
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html#levenshtein_match |
166
|
|
|
* |
167
|
|
|
* @param string|object $path |
168
|
|
|
* @param string|object $target |
169
|
|
|
* @param int|object $distance |
170
|
|
|
* @param null|bool|object $transpositions |
171
|
|
|
* @param null|int|object $maxTerms |
172
|
|
|
* @param null|string|object $prefix |
173
|
|
|
* @return FunctionExpression |
174
|
|
|
*/ |
175
|
2 |
|
public function levenshteinMatch( |
176
|
|
|
mixed $path, |
177
|
|
|
mixed $target, |
178
|
|
|
mixed $distance, |
179
|
|
|
mixed $transpositions = null, |
180
|
|
|
mixed $maxTerms = null, |
181
|
|
|
mixed $prefix = null |
182
|
|
|
): FunctionExpression { |
183
|
2 |
|
$arguments = [ |
184
|
2 |
|
"path" => $path, |
185
|
2 |
|
"target" => $target, |
186
|
2 |
|
"distance" => $distance, |
187
|
2 |
|
"transpositions" => $transpositions, |
188
|
2 |
|
"maxTerms" => $maxTerms, |
189
|
2 |
|
"prefix" => $prefix, |
190
|
|
|
]; |
191
|
2 |
|
$arguments = $this->unsetNullValues($arguments); |
192
|
|
|
|
193
|
2 |
|
return new FunctionExpression('LEVENSHTEIN_MATCH', $arguments); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Check whether the pattern search is contained in the attribute denoted by path, using wildcard matching. |
198
|
|
|
* |
199
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html#like |
200
|
|
|
*/ |
201
|
1 |
|
public function like( |
202
|
|
|
string|object $path, |
203
|
|
|
mixed $search |
204
|
|
|
): FunctionExpression { |
205
|
1 |
|
$arguments = [ |
206
|
1 |
|
"path" => $path, |
207
|
1 |
|
"search" => $search, |
208
|
|
|
]; |
209
|
|
|
|
210
|
1 |
|
return new FunctionExpression('LIKE', $arguments); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Match documents with a Damerau-Levenshtein distance lower than or equal to |
215
|
|
|
* the distance between the stored attribute value and target. |
216
|
|
|
* |
217
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html#levenshtein_match |
218
|
|
|
* |
219
|
|
|
* @param string|object $path |
220
|
|
|
* @param string|object $target |
221
|
|
|
* @param null|int|float|object $threshold |
222
|
|
|
* @param null|string|object $analyzer |
223
|
|
|
* @return FunctionExpression |
224
|
|
|
*/ |
225
|
2 |
|
public function nGramMatch( |
226
|
|
|
mixed $path, |
227
|
|
|
mixed $target, |
228
|
|
|
mixed $threshold = null, |
229
|
|
|
mixed $analyzer = null |
230
|
|
|
): FunctionExpression { |
231
|
2 |
|
$arguments = [ |
232
|
2 |
|
"path" => $path, |
233
|
2 |
|
"target" => $target, |
234
|
2 |
|
"threshold" => $threshold, |
235
|
2 |
|
"analyzer" => $analyzer |
236
|
|
|
]; |
237
|
2 |
|
$arguments = $this->unsetNullValues($arguments); |
238
|
|
|
|
239
|
2 |
|
return new FunctionExpression('NGRAM_MATCH', $arguments); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Search for a phrase in the referenced attribute. |
244
|
|
|
* |
245
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-arangosearch.html#phrase |
246
|
|
|
*/ |
247
|
3 |
|
public function phrase(): FunctionExpression |
248
|
|
|
{ |
249
|
3 |
|
$arguments = func_get_args(); |
250
|
|
|
|
251
|
3 |
|
return new FunctionExpression('PHRASE', $arguments); |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths