Oihana PHP Arango

HasFacetEdge uses trait:short

Builds the AQL filter fragment for an {@see Facet::EDGE} facet: it keeps documents linked (or, when negated, not linked) to a target vertex through an inbound edge traversal. The match is driven by {@see HasFacetSimpleConditions} — a configurable operator (`Facet::OP`, default `eq`) over one or more vertex fields (`AQL::FIELDS`, default `_key`). Composed via {@see FacetTrait}.

Matching several fields with op = like makes this facet a full-text-ish lookup over a linked vocabulary (the former THESAURUS facet, now just an EDGE configuration).

Tags
see
FacetTrait::prepareFacets()

The dispatcher that invokes this builder.

HasFacetSimpleConditions

The shared value-matching logic.

Table of Contents

Methods

prepareFacetEdge()  : string
Prepares a facet condition with an edge definition.
prepareSimpleConditions()  : string
Builds a simple existential facet expression.
simpleLength()  : string
Wraps a set of OR-ed term groups into `LENGTH(FOR … FILTER [prefix &&] (…) RETURN …)`.

Methods

prepareFacetEdge()

Prepares a facet condition with an edge definition.

protected prepareFacetEdge(string $key, mixed $value, array<string|int, mixed> &$binds, array<string|int, mixed> $facet, string $doc) : string
Parameters
$key : string
$value : mixed
$binds : array<string|int, mixed>
$facet : array<string|int, mixed>
$doc : string
Tags
throws
BindException
ReflectionException
example

Set the facetable definition in the model :

Arango::FACETS =>
[
    Prop::LOCATION =>
    [
       Facet::TYPE => Facet::EDGE ,
       Facet::EDGE => 'organizations_places'
    ]
]

Exact match on _key (default operator eq, single field) :

?facets={"location":1234}          // linked to vertex 1234
?facets={"location":"1234,5678"}   // linked to 1234 OR 5678
?facets={"location":"-1234"}       // NOT linked to 1234        (LENGTH(...) == 0)
?facets={"location":"1234,-5678"}  // linked to 1234 AND not linked to 5678

Search several vertex fields with like (the former THESAURUS) :

Prop::SUBJECTS =>
[
    Facet::TYPE => Facet::EDGE ,
    Facet::EDGE => 'has_subject' ,
    AQL::FIELDS => '_key,name,alternateName' , // OR across these fields
    Facet::OP   => 'like'                      // CONTAINS-like with % wildcards
]
// ?facets={"subjects":"art"} => a linked subject whose _key, name OR alternateName LIKE @art

Values are comma-separated and OR-ed; a leading - negates a value, excluding the document. See HasFacetSimpleConditions for the full operator catalogue and multi-field behaviour.

Return values
string

prepareSimpleConditions()

Builds a simple existential facet expression.

protected prepareSimpleConditions(mixed $value, array<string|int, mixed> $facet, string $forSource, string|null $prefix, string $docRef, string $key, array<string|int, mixed> &$binds, string $return) : string

Positive values are matched inside a LENGTH(FOR … FILTER [prefix &&] (… OR …) …) > 0 clause; negated values are excluded with a twin LENGTH(…) == 0 clause; both are AND-ed (and parenthesized) when present.

Parameters
$value : mixed

The facet value: a scalar, a CSV string, a list, or an {op, val} object.

$facet : array<string|int, mixed>

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

$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_location).

$key : string

The facet key, used to namespace the bind names.

$binds : array<string|int, mixed>

The bind variables, populated by reference.

$return : string

The compiled RETURN … clause.

Tags
throws
BindException
UnsupportedOperationException
ValidationException
Return values
string

simpleLength()

Wraps a set of OR-ed term groups into `LENGTH(FOR … FILTER [prefix &&] (…) RETURN …)`.

private simpleLength(string $forSource, string|null $prefix, array<int, string> $groups, string $return) : string
Parameters
$forSource : string
$prefix : string|null
$groups : array<int, string>
$return : string
Return values
string
On this page

Search results