Oihana PHP Arango

HasFacetJoinComplex uses trait:short

Builds the AQL filter fragment for a {@see Facet::JOIN_COMPLEX} facet: the key-join counterpart of {@see HasFacetEdgeComplex}. Instead of traversing an edge, it joins a collection by attribute equality and keeps documents that have at least one joined document matching SEVERAL fields (AND), each field accepting multiple values (OR) and per-value negation.

A join is a nested FOR matched on a key, not a graph traversal: LENGTH(FOR doc_<key> IN <collection> FILTER doc_<key>.<KEY> == doc.<PROPERTY> && …conditions… RETURN 1) > 0. The join is doc_join.<KEY> == doc.<PROPERTY> (or IN when the main document holds an array of keys), with KEY the joined side (default _key) and PROPERTY the main side (default the facet key) — which expresses both "the document holds the foreign key" and the reverse one-to-many "the joined documents reference the document".

Tags
see
FacetTrait::prepareFacets()

The dispatcher that invokes this builder.

HasFacetComplexConditions

The shared per-field condition builder.

Table of Contents

Methods

prepareComplexConditions()  : array<int, string>
Builds the list of AQL conditions for an object of `field: condition` pairs, each tested on the related document `$docRef`.
prepareFacetJoinComplex()  : string
Prepares a join complex facet.

Methods

prepareComplexConditions()

Builds the list of AQL conditions for an object of `field: condition` pairs, each tested on the related document `$docRef`.

protected prepareComplexConditions(mixed $value, string $docRef, string $key, array<string|int, mixed> &$binds[, mixed $alt = null ]) : array<int, string>

Every condition applies to the same related document, so per-value negation stays inline (!=) and a field given an array OR-es its values (flipping to AND when a negative term is present, mirroring HasFacetField). Each sub-field name is validated with assertAttributeName() before being interpolated, guarding against AQL injection.

A facet-wide alt (from the definition) wraps EVERY sub-field comparison symmetrically — its key-side chain wraps each related field, its value-side chain wraps each bound value (e.g. LOWER(v.value) == LOWER(@0)). Per sub-field alt is not (yet) supported — see static::prepareComplexConditions().

Parameters
$value : mixed

The object of field: condition pairs.

$docRef : string

The related-document variable (e.g. doc_numbers).

$key : string

The facet key, used to namespace the bind names.

$binds : array<string|int, mixed>

The bind variables, populated by reference.

$alt : mixed = null

The facet-wide alt chain (from Facet::ALT), applied to every sub-field; null for none.

Tags
throws
BindException
UnsupportedOperationException
ValidationException
Return values
array<int, string>

The AQL conditions (to AND together).

prepareFacetJoinComplex()

Prepares a join complex facet.

protected prepareFacetJoinComplex(string $key, mixed $value, array<string|int, mixed> &$binds, array<string|int, mixed> $facet, string $doc) : string
Parameters
$key : string

The facet key (also the default main-side join property).

$value : mixed

The object of field: condition pairs tested on the joined document.

$binds : array<string|int, mixed>

The bind variables, populated by reference.

$facet : array<string|int, mixed>

The facet definition (AQL::COLLECTION, AQL::KEY, Facet::PROPERTY, AQL::ARRAY).

$doc : string

The main document reference.

Tags
throws
BindException
ReflectionException
UnsupportedOperationException
ValidationException
example

Reverse one-to-many — the joined documents reference the main one :

Arango::FACETS =>
[
    Prop::COMMENTS =>
    [
        Facet::TYPE     => Facet::JOIN_COMPLEX ,
        AQL::COLLECTION => 'comments' ,
        AQL::KEY        => 'articleId' ,  // joined side (default _key)
        Facet::PROPERTY => '_key'         // main side  (default the facet key)
    ]
]

One-to-one — the main document holds the foreign key (defaults: KEY=_key, PROPERTY=facet key) :

Prop::PLACE => [ Facet::TYPE => Facet::JOIN_COMPLEX , AQL::COLLECTION => 'places' ]

One-to-many by array — the main document holds an array of keys :

Prop::TAGS => [ Facet::TYPE => Facet::JOIN_COMPLEX , AQL::COLLECTION => 'tags' , AQL::ARRAY => true , Facet::PROPERTY => 'tagIds' ]

Use the facet (sub-fields behave exactly like EDGE_COMPLEX) :

?facets={"comments":{"status":"approved"}}                 // a comment with status == approved
?facets={"comments":{"status":"approved","score":"5"}}     // status == approved AND score == 5
?facets={"comments":{"status":["approved","featured"]}}    // status == approved OR featured
?facets={"comments":{"status":"-spam"}}                    // a comment whose status != spam
Return values
string
On this page

Search results