Oihana PHP Arango

HasFacetIn

Builds the AQL filter fragment for an {@see Facet::IN} facet: array membership between the requested values and a document array property `doc.<property>`, driven by an operator (`op`) that reuses the filter vocabulary ({@see FilterArrayComparator}: `any.in` default, `all.in`, `none.in`, …).

This is the single primitive of the "field"-family list facets: HasFacetListField (LIST_FIELD / LIST_FIELD_SORTED) and HasFacetList (LIST) delegate here. Composed via FacetTrait.

Operand orientation is TO_ARRAY([@v0,@v1,...]) <op> doc.<property> (the requested values on the left), so all.in reads as "the document has ALL the requested values" — the natural multi-select semantics, and intentionally the mirror of the ?filter= ARRAY orientation (doc.field <op> [values]).

Tags
see
FacetTrait::prepareFacets()

The dispatcher that invokes this builder.

Table of Contents

Methods

prepareFacetIn()  : string
Prepares an array membership facet.

Methods

prepareFacetIn()

Prepares an array membership facet.

protected prepareFacetIn(string $key, mixed $value, array<string|int, mixed> &$binds, array<string|int, mixed> $facet, string $doc[, bool $sortable = false ]) : string
Parameters
$key : string

The facet key (also the default document array property).

$value : mixed

Either a CSV string ("a,b"), a list (["a","b"]) or an {op, val} object selecting the operator per request.

$binds : array<string|int, mixed>

The bind variables, populated by reference.

$facet : array<string|int, mixed>

The facet definition (Facet::PROPERTY, Facet::OP).

$doc : string

The document reference the array is read from.

$sortable : bool = false

When true, append SORT POSITION(...) to order by the requested values.

Tags
throws
BindException
UnsupportedOperationException
ValidationException
example

Set the facetable definition in the model (operator optional, defaults to any.in; it can also be overridden per request) :

Arango::FACETS =>
[
    Prop::KEYWORDS =>
    [
        Facet::TYPE     => Facet::IN ,
        Facet::PROPERTY => Prop::KEYWORDS ,
        Facet::OP       => FilterArrayComparator::ANY_IN // optional default
    ]
]

Value forms — a CSV string, a list, or an {op, val} object :

?facets={"keywords":"cuisine,jardin"}                        // ANY IN  : has cuisine OR jardin
?facets={"keywords":["cuisine","jardin"]}                    // ANY IN  : array form, same result
?facets={"keywords":{"op":"all.in","val":"cuisine,jardin"}}  // ALL IN  : has BOTH values
?facets={"keywords":{"op":"none.in","val":["cuisine"]}}      // NONE IN : has NEITHER value
?facets={"keywords":{"op":"any.nin","val":"cuisine,jardin"}} // ANY NOT IN

Operator codes reuse the filter vocabulary (FilterArrayComparator): any.in (default), all.in, none.in, any.nin, all.nin, none.nin, …

Property aliasing — the URL facet key is decoupled from the document property via Facet::PROPERTY (e.g. expose id but target _key):

Arango::FACETS => [ 'id' => [ Facet::TYPE => Facet::IN , Facet::PROPERTY => '_key' ] ]
?facets={"id":"k1,k2"}   // => TO_ARRAY([@id_0,@id_1]) ANY IN doc._key

Generated AQL (default any.in) :

TO_ARRAY([@keywords_0,@keywords_1]) ANY IN doc.keywords

With $sortable = true (the Facet::LIST_FIELD_SORTED entry point), a SORT POSITION(...) clause is appended to rank by the requested order :

TO_ARRAY([@keywords_0,@keywords_1]) ANY IN doc.keywords SORT POSITION([@keywords_0,@keywords_1],doc.keywords,true)
Return values
string
On this page

Search results