Oihana PHP Arango

HasFacetEdgeAggregate uses trait:short

Builds the AQL filter fragment for an {@see \oihana\arango\models\enums\Facet::EDGE_AGGREGATE} facet: the aggregate counterpart of {@see HasFacetEdge}. Instead of testing for the mere existence of a linked vertex, it aggregates a numeric field over ALL vertices reached through an inbound edge traversal and compares the result to a threshold — `AGG(FOR doc_<key> IN INBOUND doc <edge> RETURN doc_<key>.<field>) <op> @<key>_0`.

The aggregation logic (aggregator / field / comparator / threshold resolution) is shared with HasFacetJoinAggregate through HasFacetAggregateConditions; only the iteration source differs (an INBOUND traversal — no FILTER needed, the traversal already targets the right vertices).

Tags
see
FacetTrait::prepareFacets()

The dispatcher that invokes this builder.

HasFacetAggregateConditions

The shared aggregation logic.

Table of Contents

Methods

prepareAggregateConditions()  : string
Builds an aggregate facet expression.
prepareFacetEdgeAggregate()  : string
Prepares an edge aggregate facet.

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[, array<string|int, mixed> $init = [] ]) : 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.

$init : array<string|int, mixed> = []
Tags
throws
BindException
ValidationException

When the aggregator is unknown or a non-count aggregate has no valid field.

DependencyException
NotFoundException
Return values
string

The AQL fragment, or an empty string when no threshold is supplied.

prepareFacetEdgeAggregate()

Prepares an edge aggregate facet.

protected prepareFacetEdgeAggregate(string $key, mixed $value, array<string|int, mixed> &$binds, array<string|int, mixed> $facet, string $doc[, array<string|int, mixed> $init = [] ]) : string
Parameters
$key : string

The facet key (also the related-document variable suffix).

$value : mixed

A scalar threshold, or an {agg, field, op, val} object.

$binds : array<string|int, mixed>

The bind variables, populated by reference.

$facet : array<string|int, mixed>

The facet definition (AQL::EDGE, Facet::AGG, AQL::FIELDS, Facet::OP).

$doc : string

The main document reference.

$init : array<string|int, mixed> = []
Tags
throws
BindException
ReflectionException
ValidationException
example

Average revenue of all linked balance sheets — keep organisations above a threshold :

Arango::FACETS =>
[
    'balanceSheets' =>
    [
        Facet::TYPE => Facet::EDGE_AGGREGATE ,
        AQL::EDGE   => 'balance_edges' , // edge collection (INBOUND doc)
        Facet::AGG  => 'avg' ,           // default aggregator
        AQL::FIELDS => 'revenue' ,       // default aggregated field
        Facet::OP   => 'ge'              // default threshold comparator
    ]
]
?facets={"balanceSheets":{"agg":"avg","field":"revenue","op":"ge","val":1000000}}
// AVERAGE(FOR doc_balanceSheets IN INBOUND doc balance_edges RETURN doc_balanceSheets.revenue) >= @balanceSheets_0

?facets={"balanceSheets":{"agg":"count","op":"ge","val":3}}  // at least 3 linked balance sheets
?facets={"balanceSheets":{"agg":"sum","field":"revenue","val":5000000}}  // cumulative revenue >= 5M
?facets={"balanceSheets":5}  // defaults (count, ge): at least 5 linked balance sheets
Return values
string
On this page

Search results