Oihana PHP Arango

FacetCountsQueryTrait

Builds the AQL query that computes per-value **facet counts** for several dimensions at once, alongside (not replacing) the document list.

Each requested dimension is a key of the model's $this->facets whitelist (the filterable facets become the counted facets). One LET sub-query per dimension counts values over the same conjunctive filter as the list, so the buckets reflect the currently filtered set:

LET category = (FOR doc IN @@coll FILTER <same filters> COLLECT value = doc.category WITH COUNT INTO count SORT count DESC RETURN { value, count })
LET status   = (FOR doc IN @@coll FILTER <same filters> COLLECT value = doc.status   WITH COUNT INTO count SORT count DESC RETURN { value, count })
RETURN { category, status }

v1 supports the scalar Facet::FIELD and the array-membership Facet::IN family (Facet::LIST, Facet::LIST_FIELD, Facet::LIST_FIELD_SORTED); other facet types are skipped. A Facet::PROPERTY carrying the [*] array-expansion marker (e.g. offers[*].priceCurrency) unwinds the object array and counts the sub-field per element — see FacetCountsQueryTrait::buildFacetCountSubquery().

Tags
see
FacetCountsQueryTrait::buildFacetCountsQuery()

The entry point.

Table of Contents

Constants

FACET_COUNT_ITEM  : string = 'item'
The unwind loop variable for array-membership facets (kept distinct from {@see FacetCountsQueryTrait::FACET_COUNT_VALUE} to avoid a name collision).
FACET_COUNT_VALUE  : string = 'value'
The bucket value attribute name in the returned rows (`{ value, count }`).

Methods

buildFacetCountsQuery()  : string
Builds the multi-`LET` facet-counts query, or an empty string when nothing is countable.
buildFacetCountSubquery()  : string|null
Builds one dimension's counting sub-query, or null for an unsupported type.
facetCountCollect()  : array{0: string, 1: string, 2: string}
The shared `COLLECT value = <expr> WITH COUNT INTO count SORT count DESC RETURN { value, count }` tail.

Constants

FACET_COUNT_ITEM

The unwind loop variable for array-membership facets (kept distinct from {@see FacetCountsQueryTrait::FACET_COUNT_VALUE} to avoid a name collision).

private string FACET_COUNT_ITEM = 'item'

FACET_COUNT_VALUE

The bucket value attribute name in the returned rows (`{ value, count }`).

private string FACET_COUNT_VALUE = 'value'

Methods

buildFacetCountsQuery()

Builds the multi-`LET` facet-counts query, or an empty string when nothing is countable.

public buildFacetCountsQuery([array<string|int, mixed> $init = [] ][, array<string|int, mixed> &$bindVars = [] ][, string $docRef = AQL::DOC ]) : string
Parameters
$init : array<string|int, mixed> = []

The list query options (Arango::FACET_COUNTS holds the dimensions).

$bindVars : array<string|int, mixed> = []

The bind variables, populated by reference.

$docRef : string = AQL::DOC

The document reference.

Tags
throws
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
UnsupportedOperationException
ValidationException
Return values
string

The compiled AQL query, or an empty string.

buildFacetCountSubquery()

Builds one dimension's counting sub-query, or null for an unsupported type.

private buildFacetCountSubquery(array<string|int, mixed> $facet, string $key, string $for, string|null $filter, string $docRef) : string|null
Parameters
$facet : array<string|int, mixed>

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

$key : string

The facet key (default property).

$for : string

The pre-built FOR segment shared by every dimension — the bound collection, or the bound View with its SEARCH segment when the View search is active.

$filter : string|null

The shared FILTER clause.

$docRef : string

The document reference.

Tags
throws
ReflectionException
UnsupportedOperationException
ValidationException
Return values
string|null

facetCountCollect()

The shared `COLLECT value = <expr> WITH COUNT INTO count SORT count DESC RETURN { value, count }` tail.

private facetCountCollect(string $expression, string $sort) : array{0: string, 1: string, 2: string}
Parameters
$expression : string

The value expression to group on.

$sort : string

The pre-built SORT count DESC clause.

Tags
throws
ReflectionException
UnsupportedOperationException
Return values
array{0: string, 1: string, 2: string}

[ COLLECT, SORT, RETURN ] fragments.

On this page

Search results