View
Operations scoped to a single ArangoSearch view on the server.
Instances are obtained through Database::view() or
Database::createView(). The view name is fixed at
construction time and is interpolated into the
/_api/view/{name}[/properties] routes by the helpers below.
The class covers the full lifecycle of a view: creation,
existence probe, raw description, full properties read,
partial update (PATCH — additive on links), total replace
(PUT — wipes everything not in the payload), and drop. The
rename operation is intentionally not exposed in V1 (parity
with Analyzer which has
no rename either, and the operation is not supported on cluster
deployments).
Both view types are covered: arangosearch (the view owns its
inverted index through links, via create()) and
search-alias (a thin alias over per-collection inverted
indexes, via createSearchAlias()).
Example:
$articles = $db->collection( 'articles' ) ;
$articles->create() ;
$textEn = $db->createAnalyzer( 'text_en' , new TextAnalyzer( locale : 'en' ) , [
AnalyzerFeature::FREQUENCY ,
AnalyzerFeature::POSITION ,
AnalyzerFeature::NORM ,
] ) ;
$view = $db->createView
(
'articles_view' ,
links :
[
'articles' => new ArangoSearchLink
(
fields :
[
'title' => new ArangoSearchLink( analyzers : [ 'text_en' ] ) ,
'body' => new ArangoSearchLink( analyzers : [ 'text_en' ] ) ,
] ,
) ,
] ,
) ;
$cursor = $db->query
(
aql( 'FOR doc IN articles_view SEARCH ANALYZER(doc.title IN TOKENS(?, ?), ?) RETURN doc' ,
'hello' , 'text_en' , 'text_en' ) ,
) ;
Tags
Table of Contents
Constants
- PROPERTIES_SUB_ROUTE : string = '/properties'
- Sub-route exposing the per-view configuration (`/_api/view/{name}/properties`).
Properties
Methods
- __construct() : mixed
- create() : array<string, mixed>
- Creates this view on the server.
- createSearchAlias() : array<string, mixed>
- Creates this view on the server as a `search-alias` view.
- drop() : void
- Drops this view from the server.
- exists() : bool
- Returns true when this view currently exists on the server.
- get() : array<string, mixed>
- Returns the raw server-side description of this view (`GET /_api/view/{name}`).
- getName() : string
- Returns the view name this instance is bound to.
- properties() : array<string, mixed>
- Returns the full per-view configuration (`GET /_api/view/{name}/properties`).
- replaceProperties() : array<string, mixed>
- Replaces the per-view configuration in full (`PUT /_api/view/{name}/properties`).
- updateProperties() : array<string, mixed>
- Merges new fields into the per-view configuration (`PATCH /_api/view/{name}/properties`).
- normaliseLinkNode() : array<string, mixed>|object
- Recursively shapes a link node for the wire: descends the `fields` map and turns every empty node into an empty JSON **object**.
- normaliseLinks() : array<string, array<string, mixed>>
- Walks a `links` map and turns every {@see ArangoSearchLink} value object into its array shape, leaving plain arrays untouched.
- normalisePropertiesBody() : array<string, mixed>
- Applies {@see normaliseLinks()} to a properties body when the `links` key is present. Pure function — leaves the other keys untouched and never mutates the input.
- path() : string
- Builds the `/_api/view/{name}` path with the view name URL-encoded.
Constants
PROPERTIES_SUB_ROUTE
Sub-route exposing the per-view configuration (`/_api/view/{name}/properties`).
private
string
PROPERTIES_SUB_ROUTE
= '/properties'
Properties
$database
public
Database
$database
$name
public
string
$name
Methods
__construct()
public
__construct(Database $database, string $name) : mixed
Parameters
- $database : Database
-
Parent database (provides the shared HTTP transport).
- $name : string
-
Name of the target view on the server.
create()
Creates this view on the server.
public
create([array<string, ArangoSearchLink|array<string, mixed>> $links = [] ][, array<string, mixed> $options = [] ]) : array<string, mixed>
Wraps POST /_api/view. The view name and type are taken
from $name and forced to
ViewType::ARANGOSEARCH — for a search-alias view use
createSearchAlias() instead.
$links is the per-collection link map: keys are collection
names, values are ArangoSearchLink instances describing
how each field of the collection is indexed. Plain arrays are
accepted as well — useful when round-tripping a server-side
description through create().
$options is forwarded verbatim as the rest of the create
body. Recognised keys include cleanupIntervalStep,
consolidationIntervalMsec, commitIntervalMsec,
consolidationPolicy, writebufferIdle,
writebufferActive, writebufferSizeMax, primarySort,
storedValues.
Parameters
- $links : array<string, ArangoSearchLink|array<string, mixed>> = []
-
Per-collection link map.
- $options : array<string, mixed> = []
-
Extra arangosearch options forwarded verbatim.
Tags
Return values
array<string, mixed> —Raw view description as returned by the server.
createSearchAlias()
Creates this view on the server as a `search-alias` view.
public
createSearchAlias([array<int, array{collection: string, index: string}> $indexes = [] ][, array<string, mixed> $options = [] ]) : array<string, mixed>
Wraps POST /_api/view with the search-alias type. Unlike an
arangosearch view (which owns its inverted index through links), a
search-alias view is a thin alias over one inverted index per
collection, referenced through $indexes.
$indexes is the server-ready list of {collection, index} entries
(e.g. the output of
SearchAliasView::getIndexes()).
$options is forwarded verbatim as the rest of the create body.
Parameters
- $indexes : array<int, array{collection: string, index: string}> = []
-
The
{collection, index}entries. - $options : array<string, mixed> = []
-
Extra options forwarded verbatim.
Tags
Return values
array<string, mixed> —Raw view description as returned by the server.
drop()
Drops this view from the server.
public
drop() : void
Wraps DELETE /_api/view/{name}. Underlying source
collections are NOT touched — only the view metadata and
its inverted index are removed.
Tags
exists()
Returns true when this view currently exists on the server.
public
exists() : bool
Treats a 404 as a clean "missing" and rethrows everything else.
Tags
Return values
boolget()
Returns the raw server-side description of this view (`GET /_api/view/{name}`).
public
get() : array<string, mixed>
Carries type / id / globallyUniqueId / name only —
call properties() for the full configuration
(links, consolidation, writebuffer, …).
Tags
Return values
array<string, mixed>getName()
Returns the view name this instance is bound to.
public
getName() : string
Return values
stringproperties()
Returns the full per-view configuration (`GET /_api/view/{name}/properties`).
public
properties() : array<string, mixed>
Includes every field exposed by the arangosearch type:
links, cleanupIntervalStep, consolidationIntervalMsec,
commitIntervalMsec, consolidationPolicy,
writebufferIdle, writebufferActive,
writebufferSizeMax, primarySort, storedValues, plus
the four top-level fields (get()).
Tags
Return values
array<string, mixed>replaceProperties()
Replaces the per-view configuration in full (`PUT /_api/view/{name}/properties`).
public
replaceProperties([array<string, mixed> $properties = [] ]) : array<string, mixed>
Every field absent from the payload reverts to the server's
default — in particular, sending links: [] wipes every
existing link. Use updateProperties() for an additive
merge.
$properties['links'] may carry ArangoSearchLink
value objects, plain arrays, or a mix — they are normalised
recursively before the request leaves.
Parameters
- $properties : array<string, mixed> = []
-
New configuration.
Tags
Return values
array<string, mixed> —Raw properties payload as returned by the server.
updateProperties()
Merges new fields into the per-view configuration (`PATCH /_api/view/{name}/properties`).
public
updateProperties([array<string, mixed> $properties = [] ]) : array<string, mixed>
The merge is additive on links: sending
links: { collA: {...} } updates collA but leaves any
other linked collection untouched. To drop links, use
replaceProperties() with an empty links map.
$properties['links'] may carry ArangoSearchLink
value objects, plain arrays, or a mix — they are normalised
recursively before the request leaves.
Parameters
- $properties : array<string, mixed> = []
-
Partial configuration.
Tags
Return values
array<string, mixed> —Raw properties payload as returned by the server.
normaliseLinkNode()
Recursively shapes a link node for the wire: descends the `fields` map and turns every empty node into an empty JSON **object**.
private
normaliseLinkNode(array<string, mixed> $node) : array<string, mixed>|object
A link node is always a JSON object server-side, but json_encode([])
emits [], which the server rejects as an invalid link definition. A
field whose Analyzer equals the link default is declared as an empty
node (see SearchTrait::buildViewLink()) —
it must reach the server as } to be indexed with the link defaults.
Parameters
- $node : array<string, mixed>
Return values
array<string, mixed>|object —The node, with empty entries cast to objects.
normaliseLinks()
Walks a `links` map and turns every {@see ArangoSearchLink} value object into its array shape, leaving plain arrays untouched.
private
normaliseLinks(array<string, ArangoSearchLink|array<string, mixed>> $links) : array<string, array<string, mixed>>
Parameters
- $links : array<string, ArangoSearchLink|array<string, mixed>>
Return values
array<string, array<string, mixed>>normalisePropertiesBody()
Applies {@see normaliseLinks()} to a properties body when the `links` key is present. Pure function — leaves the other keys untouched and never mutates the input.
private
normalisePropertiesBody(array<string, mixed> $properties) : array<string, mixed>
Parameters
- $properties : array<string, mixed>
Return values
array<string, mixed>path()
Builds the `/_api/view/{name}` path with the view name URL-encoded.
private
path() : string