HasFilterArray
This trait defines the array filter helpers.
Config
Defines the 'filters' property in the model (Documents) definition.
Models::PLACES => fn( ContainerInterface $container ) => new Documents
(
$container ,
Collections::PLACES ,
[
...
AQL::FILTERS =>
[
Prop::EVENTS => FilterType::ARRAY ,
...
]
...
Tags
Table of Contents
Methods
- buildMatchCondition() : string
- Builds a `match` condition over an array of objects — a multi-field test on the ELEMENTS, not a question about how many there are.
- prepareFilterArray() : string
- Prepares the filter clause with a string attribute.
- prepareFilterArrayComparator() : string
- Prepares the filter clause with a specific operator.
- prepareFilterArrayKey() : string
- Prepares the filter clause of a string attribute with a specific key and document.
- prepareFilterAtLeast() : string
- Builds an `AT LEAST (n)` array quantifier filter: at least `n` elements of the array satisfy the comparison.
- prepareFilterQuantified() : string
- Builds a quantified comparison on a scalar array via the `quant` key: how many elements satisfy the comparison.
- elementLookup() : string
- Writes the lookup of an element of a list : `@v IN doc.offers[*].seller.id`, one per value, joined by `||`.
- elementsExist() : string
- Whether at least one element of a list satisfies a condition : `LENGTH( doc.offers[* FILTER <condition>] ) > 0`.
- isElementLookup() : bool
- Whether a filter on an element of a list (`offers[*].seller.id`) may be written as the lookup of that element — the conditions the list, the `alt` and the `quant` set, whatever the value asked for.
- lookupValues() : array<int, int|float|string|bool>|null
- The values an element is looked up for, or `null` when the filter asks another question than « does the list hold one of these values ? ».
- quantifiedArrayCondition() : string
- Builds a quantified condition over a scalar array, in the one shape that counts correctly: `array[? <quantifier> FILTER CURRENT <cmp> @value]`.
- singleMatch() : array{0: string, 1: int|float|string|bool}|null
- The sub-field and the value of a `match` written in its simple form on **one** sub-field with a scalar value (`{"label":"x"}`), or `null` for any other `match` : several sub-fields ask about one element at once, which two lookups would not say, and the `all` / `any` / `none` forms carry their own operators.
Methods
buildMatchCondition()
Builds a `match` condition over an array of objects — a multi-field test on the ELEMENTS, not a question about how many there are.
protected
buildMatchCondition(array<string|int, mixed> $match, array<string|int, mixed>|null &$binds, string $baseKey, array<string|int, mixed> $allowedFields, mixed $alt, mixed $quant[, string $at = Char::EMPTY ]) : string
🔑 Shared by both depths on purpose. The flat lookup reaches it for a key
written at the root (attachments[*]), the hierarchical walk for one written
behind an object (resolution.steps[*]). They used to build it separately, and
only one of them built it at all: the walk answered a bare cardinality instead,
silently replacing the caller's question with another one. One builder is the
point of this method — the two callers now differ only in what they hand it.
Parameters
- $match : array<string|int, mixed>
-
The match payload (sub-field => value, …).
- $binds : array<string|int, mixed>|null
-
The bind variables, populated by reference.
- $baseKey : string
-
The fully qualified AQL key of the array (
doc.attachments,doc.resolution.steps). - $allowedFields : array<string|int, mixed>
-
The declared sub-fields. Empty means no validation, so a caller that cannot resolve them must say so rather than pass
[]. - $alt : mixed
-
The resolved
altchain, applied inside the inline condition. - $quant : mixed
-
The element-axis quantifier, or null for the existential form.
- $at : string = Char::EMPTY
-
The list as the request spelled it (
attachments[*]), named by the refusal of an undeclared sub-field.
Tags
Return values
stringprepareFilterArray()
Prepares the filter clause with a string attribute.
protected
prepareFilterArray([array<string|int, mixed> $init = [] ][, array<string|int, mixed>|null &$binds = null ][, string $docRef = AQL::DOC ]) : string
Parameters
- $init : array<string|int, mixed> = []
- $binds : array<string|int, mixed>|null = null
- $docRef : string = AQL::DOC
Tags
Return values
stringprepareFilterArrayComparator()
Prepares the filter clause with a specific operator.
protected
prepareFilterArrayComparator([array<string|int, mixed> $init = [] ]) : string
Parameters
- $init : array<string|int, mixed> = []
Tags
Return values
stringprepareFilterArrayKey()
Prepares the filter clause of a string attribute with a specific key and document.
protected
prepareFilterArrayKey([string|array<string|int, mixed>|null $init = [] ][, string $docRef = AQL::DOC ][, array<string|int, mixed>|null &$binds = null ]) : string
Parameters
- $init : string|array<string|int, mixed>|null = []
- $docRef : string = AQL::DOC
- $binds : array<string|int, mixed>|null = null
Tags
Return values
stringprepareFilterAtLeast()
Builds an `AT LEAST (n)` array quantifier filter: at least `n` elements of the array satisfy the comparison.
protected
prepareFilterAtLeast(array<string|int, mixed> $init[, array<string|int, mixed>|null &$binds = null ][, string $docRef = AQL::DOC ]) : string
The operator is the array form ["atLeast.<cmp>", n] (element 0 is the
atLeast.<cmp> code, element 1 the threshold, defaulting to 1). The <cmp>
suffix reuses FilterComparator (eq, ne, gt, ge, lt, le,
in, nin). The threshold is cast to an int and inlined (injection-safe);
the value is bound. The compared key stays alt-aware.
doc.scores AT LEAST (2) >= @value
Parameters
- $init : array<string|int, mixed>
-
The filter init (
op=["atLeast.<cmp>", n]). - $binds : array<string|int, mixed>|null = null
-
The bind variables, populated by reference.
- $docRef : string = AQL::DOC
-
The document reference.
Tags
Return values
stringprepareFilterQuantified()
Builds a quantified comparison on a scalar array via the `quant` key: how many elements satisfy the comparison.
protected
prepareFilterQuantified(array<string|int, mixed> $init[, array<string|int, mixed>|null &$binds = null ][, string $docRef = AQL::DOC ]) : string
The comparator stays in op (a plain FilterComparator code such as
ge); the element-axis quantifier comes from quant and is resolved by
resolveQuantifier into ANY / ALL /
NONE / AT LEAST (n). This is the unified, recommended form; the legacy
op:"all.ge" and op:["atLeast.ge", n] notations remain valid aliases.
doc.scores ALL >= @value
doc.scores AT LEAST (2) >= @value
Parameters
- $init : array<string|int, mixed>
-
The filter init (
op= comparator code,quant= quantifier). - $binds : array<string|int, mixed>|null = null
-
The bind variables, populated by reference.
- $docRef : string = AQL::DOC
-
The document reference.
Tags
Return values
stringelementLookup()
Writes the lookup of an element of a list : `@v IN doc.offers[*].seller.id`, one per value, joined by `||`.
private
elementLookup(string $baseKey, string $field, array<int, int|float|string|bool> $values, array<string|int, mixed>|null &$binds) : string
🚨 One IN per value, never ANY IN. doc.offers[*].seller.id ANY IN @values
says the same thing, and ArangoDB does not look it up in the index — measured, as
for INTERSECTION(). A list of IN joined by || is looked up value by value.
An empty list names no document : it is written false, which is what the
existential spelling answered.
Parameters
- $baseKey : string
-
The fully qualified key of the list (
doc.offers). - $field : string
-
The sub-field of an element (
seller.id), already checked as a name. - $values : array<int, int|float|string|bool>
-
The values to look up, distinct ; none names no document.
- $binds : array<string|int, mixed>|null
-
The bind variables, populated by reference.
Tags
Return values
stringelementsExist()
Whether at least one element of a list satisfies a condition : `LENGTH( doc.offers[* FILTER <condition>] ) > 0`.
private
elementsExist(string $baseKey, string $condition) : string
🚨 A list held inside another list is flattened before it is counted.
doc.stops[*].scans[* FILTER …] yields one list PER STOP, and its length is the
number of stops : counted as is, a parcel with one stop and no matching scan was
selected, whatever the value asked for. The elements are filtered where they are,
then flattened by as many levels as the base key crosses lists
(FLATTEN( doc.stops[*].scans[* FILTER …] , 1 )), and only then counted.
Filtering before flattening keeps a stop without scans out of the count : its
expansion is empty, where flattening first would lift a null into the list.
⚠️ A quant never reaches such a list : the hierarchical walk forwards it
on a list of the first level only, the level it would count being ambiguous
below, and the existential form is kept, as documented.
Parameters
- $baseKey : string
-
The fully qualified key of the list (
doc.offers,doc.stops[*].scans). - $condition : string
-
The inline condition on an element (
CURRENT.…).
Return values
stringisElementLookup()
Whether a filter on an element of a list (`offers[*].seller.id`) may be written as the lookup of that element — the conditions the list, the `alt` and the `quant` set, whatever the value asked for.
private
isElementLookup(string $baseKey, mixed $alt, mixed $quant) : bool
🔑 Every other filter keeps the existential spelling, each for its reason :
- an
alttransformsCURRENT, which an index does not hold transformed ; - a
quantother thananycounts the elements, anINonly finds one ; - a nested list (
employee[*].contactPoint[*].verified) expands into a list of lists, in which anINwould look for the value among lists.
The value is the other half of the question : self::lookupValues() and self::singleMatch().
Parameters
- $baseKey : string
-
The fully qualified key of the list (
doc.offers). - $alt : mixed
-
The resolved
altchain, or null. - $quant : mixed
-
The element-axis quantifier, or null.
Return values
boollookupValues()
The values an element is looked up for, or `null` when the filter asks another question than « does the list hold one of these values ? ».
private
lookupValues(mixed $operator, mixed $value) : array<int, int|float|string|bool>|null
- an equality (
eq, or no operator) on a scalar : that value ; inon a list of scalars, up to FilterLookup::MAX_VALUES once the duplicates are gone : those values, the empty list included.
Anything else — another comparator, a null, a list holding a null, an object
or a list, a list longer than the bound — answers null, and the filter keeps the
existential spelling, which answers the same documents without the index.
Parameters
- $operator : mixed
-
The comparator of the filter.
- $value : mixed
-
The value of the filter.
Return values
array<int, int|float|string|bool>|nullquantifiedArrayCondition()
Builds a quantified condition over a scalar array, in the one shape that counts correctly: `array[? <quantifier> FILTER CURRENT <cmp> @value]`.
private
quantifiedArrayCondition(array<string|int, mixed> $init, array<string|int, mixed>|null &$binds, string $docRef, string $quantifier, string $comparator) : string
🚨 Not the infix array comparison operator. doc.tags AT LEAST (3) == @v
reads naturally and is wrong: ArangoDB answers true whenever the array holds
fewer than n elements, whatever they are — [] AT LEAST (99) == "x" is
true. So "records with at least three matching tags" answered "records with
fewer than three tags", the opposite of the question, in 200.
The question-mark operator counts the elements that actually match, and it is
what the object-array branch of this same filter has always used. ANY, ALL
and NONE were correct in either spelling — measured, row for row — so all four
go through here rather than leaving two shapes in one method depending on what
quant happens to hold.
Parameters
- $init : array<string|int, mixed>
-
The filter init.
- $binds : array<string|int, mixed>|null
-
The bind variables, populated by reference.
- $docRef : string
-
The document reference.
- $quantifier : string
-
The resolved AQL quantifier (
ANY,ALL,NONE,AT LEAST (n)). - $comparator : string
-
The resolved AQL comparator applied to each element.
Tags
Return values
stringsingleMatch()
The sub-field and the value of a `match` written in its simple form on **one** sub-field with a scalar value (`{"label":"x"}`), or `null` for any other `match` : several sub-fields ask about one element at once, which two lookups would not say, and the `all` / `any` / `none` forms carry their own operators.
private
singleMatch(array<string|int, mixed> $match) : array{0: string, 1: int|float|string|bool}|null
Parameters
- $match : array<string|int, mixed>
-
The
matchpayload.