HasFacetAggregateConditions
Shared builder for the "aggregate" facets ({@see HasFacetEdgeAggregate}, {@see HasFacetJoinAggregate}): both keep documents whose related documents (reached by an edge traversal or a key-join) satisfy an aggregate condition over a numeric field — `AGG(FOR … [FILTER join] RETURN related.field) <op> @threshold`.
Only the iteration source differs (an INBOUND traversal vs a FOR over a
collection plus a join condition), so the aggregation logic lives here. It
generalizes the existential LENGTH(FOR … RETURN …) > 0 clause used by the
simple/complex facets: count + op:gt + val:0 reproduces it exactly.
The facet is driven by {agg, field, op, val}, each piece overridable per
request (URL) and falling back to the definition:
agg— the aggregator (FacetAggregator:avg,sum,min,max,count); definition defaultFacet::AGG, global defaultcount;field— the related numeric attribute to aggregate; definition defaultAQL::FIELDS; ignored bycount(which returns1); URL-provided names are validated with assertAttributeName() against AQL injection;op— the threshold comparator (FilterComparator:ge,gt,le,lt,eq,ne); definition defaultFacet::OP, global defaultge;val— the threshold; REQUIRED (absent ⇒ the facet is skipped). A bare scalar facet value is read as the threshold directly.
Neither - negation (the op already carries the direction) nor alt
(field and threshold are numeric) apply to aggregate facets.
The aggregate is guarded by LENGTH(FOR … RETURN 1) > 0, so an aggregate
facet only ever matches documents that have AT LEAST ONE related document.
This avoids the AQL empty-set surprise: AVERAGE([])/MIN([])/MAX([])
yield null (and SUM([])/COUNT([]) yield 0), and since null sorts
below every number, a lt/le threshold would otherwise spuriously match
documents with no related document at all.
Tags
Table of Contents
Methods
- prepareAggregateConditions() : string
- Builds an aggregate facet expression.
Methods
prepareAggregateConditions()
Builds an aggregate facet expression.
protected
prepareAggregateConditions(mixed $value, array<string|int, mixed> $facet, string $forSource, string|null $prefix, string $docRef, string $key, array<string|int, mixed> &$binds) : string
Resolves the aggregator, field, comparator and threshold (URL overriding
the definition), then emits
AGG(FOR … [FILTER prefix] RETURN related.field) <comparator> @<key>_0.
Parameters
- $value : mixed
-
The facet value: a scalar threshold, or an
{agg, field, op, val}object. - $facet : array<string|int, mixed>
-
The facet definition (
Facet::AGG,AQL::FIELDS,Facet::OP). - $forSource : string
-
The compiled
FOR …source (traversal or collection). - $prefix : string|null
-
An extra condition AND-ed inside the FILTER (e.g. a join match), or null.
- $docRef : string
-
The related-document variable (e.g.
doc_comments). - $key : string
-
The facet key, used to namespace the bind name.
- $binds : array<string|int, mixed>
-
The bind variables, populated by reference.
Tags
Return values
string —The AQL fragment, or an empty string when no threshold is supplied.