Oihana PHP Arango

ViewManagementTrait

View management methods shared by the {@see \oihana\arango\db\ArangoDB} façade — the ArangoSearch counterpart of {@see CollectionManagementTrait}.

Like the collection methods, every operation is defensive: a missing server or an already-existing/missing view resolves to false instead of throwing, so lazy model initialization stays safe without a database.

Tags
author

Marc Alcaraz (ekameleon)

since
1.2.0

Table of Contents

Methods

searchAliasViewCreate()  : bool
Creates a `search-alias` view if it does not already exist.
searchAliasViewDiff()  : DiffReport
Compares a `search-alias` view declaration with the server state and reports the differences — the read-only half of {@see searchAliasViewSync()}.
searchAliasViewSync()  : DiffReport
Reconciles a `search-alias` view with its declaration: creates it when missing, drop + recreate on drift, does nothing when already in sync.
viewCreate()  : bool
Creates an `arangosearch` View if it does not already exist.
viewDiff()  : DiffReport
Compares a View declaration with the server state and reports the differences — the read-only half of {@see viewSync()}.
viewDrop()  : bool
Drops a View if it exists. Underlying source collections are not touched.
viewExists()  : bool
Checks if a View exists.
viewSync()  : DiffReport
Reconciles a View with its declaration: creates it when missing, repairs a drift with `updateProperties()` (the View stays available while the inverted index rebuilds in the background — and PATCH replaces each declared collection link wholesale, so removed fields do unindex), does nothing when already in sync.
compareViewIndexes()  : array<int, string>
Accumulates one change line per `{collection, index}` pair that differs between the declared list and the server `indexes` — see {@see searchAliasViewDiff()} for the comparison semantics.
compareViewLinkNode()  : void
Recursively compares one declared link node with its server counterpart: declared keys must match (lists like `analyzers` are compared order-insensitively, server defaults that the declaration omits are ignored), and the `fields` maps are checked both ways.
compareViewLinks()  : array<int, string>
Walks the declared link map and accumulates one line per difference with the server `links` — see {@see viewDiff()} for the comparison semantics.
loadViewProperties()  : array<string, mixed>|DiffReport
Loads a view's server properties, guarding both existence and type — the shared preamble of {@see viewDiff()} and {@see searchAliasViewDiff()}.
searchAliasViewRecreate()  : bool
Drops and recreates a `search-alias` view to repair a drift — safe because the alias owns no data (the underlying inverted indexes survive).

Methods

searchAliasViewCreate()

Creates a `search-alias` view if it does not already exist.

public searchAliasViewCreate(SearchAliasView $view) : bool
Parameters
$view : SearchAliasView

The declared search-alias view.

Return values
bool

TRUE when the view has been created, FALSE when it already existed or the request failed.

searchAliasViewDiff()

Compares a `search-alias` view declaration with the server state and reports the differences — the read-only half of {@see searchAliasViewSync()}.

public searchAliasViewDiff(SearchAliasView $view) : DiffReport

The comparison is set-oriented on the {collection, index} pairs: every declared pair must be aliased on the server, and any server pair absent from the declaration is reported as drift.

Parameters
$view : SearchAliasView

The declared search-alias view.

Return values
DiffReport

The typed report — see DiffStatus for the possible statuses.

searchAliasViewSync()

Reconciles a `search-alias` view with its declaration: creates it when missing, drop + recreate on drift, does nothing when already in sync.

public searchAliasViewSync(SearchAliasView $view) : DiffReport

A search-alias view holds no data — it only references the inverted indexes declared on the collections — so a drop + recreate is safe (the underlying indexes survive) and far simpler than the per-entry add/del PATCH operations. It is not transactional: between the drop and the recreate the view briefly does not exist (search unavailable for a few ms), which is acceptable for a maintenance sync.

Parameters
$view : SearchAliasView

The declared search-alias view.

Return values
DiffReport

The searchAliasViewDiff() report, with $applied set when created or recreated.

viewCreate()

Creates an `arangosearch` View if it does not already exist.

public viewCreate(string $name[, array<string, ArangoSearchLink|array<string, mixed>> $links = [] ][, array<string, mixed> $options = [] ]) : bool
Parameters
$name : string

The name of the new View.

$links : array<string, ArangoSearchLink|array<string, mixed>> = []

Per-collection link map (collection name → link definition).

$options : array<string, mixed> = []

Extra arangosearch options forwarded verbatim (commitIntervalMsec, primarySort, …).

Return values
bool

TRUE when the View has been created, FALSE when it already existed or the request failed.

viewDiff()

Compares a View declaration with the server state and reports the differences — the read-only half of {@see viewSync()}.

public viewDiff(string $name, array<string, ArangoSearchLink|array<string, mixed>> $links) : DiffReport

The comparison is declaration-oriented: every declared key must be present and equal on the server (server-side defaults that the declaration does not mention are ignored), and fields indexed on the server but absent from the declaration are reported as drift.

Parameters
$name : string

The name of the View.

$links : array<string, ArangoSearchLink|array<string, mixed>>

Desired per-collection link map (collection name → link definition).

Return values
DiffReport

The typed report — see DiffStatus for the possible statuses.

viewDrop()

Drops a View if it exists. Underlying source collections are not touched.

public viewDrop(string $name) : bool
Parameters
$name : string

The name of the View.

Return values
bool

TRUE when the View has been dropped, FALSE otherwise.

viewExists()

Checks if a View exists.

public viewExists(string $name) : bool
Parameters
$name : string

The name of the View.

Return values
bool

viewSync()

Reconciles a View with its declaration: creates it when missing, repairs a drift with `updateProperties()` (the View stays available while the inverted index rebuilds in the background — and PATCH replaces each declared collection link wholesale, so removed fields do unindex), does nothing when already in sync.

public viewSync(string $name, array<string, ArangoSearchLink|array<string, mixed>> $links) : DiffReport

updateProperties() is preferred over replaceProperties() because it leaves the view-level options (commitIntervalMsec, …) and the links of undeclared collections untouched.

Parameters
$name : string

The name of the View.

$links : array<string, ArangoSearchLink|array<string, mixed>>

Desired per-collection link map (collection name → link definition).

Return values
DiffReport

The viewDiff() report, with $applied set when the View has been created or updated.

compareViewIndexes()

Accumulates one change line per `{collection, index}` pair that differs between the declared list and the server `indexes` — see {@see searchAliasViewDiff()} for the comparison semantics.

private compareViewIndexes(array<int, array{collection: string, index: string}> $desired, array<int, mixed> $actual) : array<int, string>
Parameters
$desired : array<int, array{collection: string, index: string}>

Declared, normalized {collection, index} list.

$actual : array<int, mixed>

Server-side indexes list (from properties()).

Return values
array<int, string>

compareViewLinkNode()

Recursively compares one declared link node with its server counterpart: declared keys must match (lists like `analyzers` are compared order-insensitively, server defaults that the declaration omits are ignored), and the `fields` maps are checked both ways.

private compareViewLinkNode(string $path, array<string, mixed> $desired, array<string, mixed> $actual, array<int, string> &$changes) : void
Parameters
$path : string

Dotted breadcrumb used in the change lines.

$desired : array<string, mixed>

Declared link node.

$actual : array<string, mixed>

Server link node.

$changes : array<int, string>

Accumulated change lines, by reference.

Walks the declared link map and accumulates one line per difference with the server `links` — see {@see viewDiff()} for the comparison semantics.

private compareViewLinks(array<string, ArangoSearchLink|array<string, mixed>> $desired, array<string, mixed> $actual) : array<int, string>
Parameters
$desired : array<string, ArangoSearchLink|array<string, mixed>>

Declared per-collection link map.

$actual : array<string, mixed>

Server-side links map (from properties()).

Return values
array<int, string>

loadViewProperties()

Loads a view's server properties, guarding both existence and type — the shared preamble of {@see viewDiff()} and {@see searchAliasViewDiff()}.

private loadViewProperties(string $name, string $expectedType) : array<string, mixed>|DiffReport
Parameters
$name : string

The view name.

$expectedType : string

The expected ViewType of the server view.

Tags
throws
ArangoException

When the server is unreachable.

Return values
array<string, mixed>|DiffReport

The server properties on success, or a terminal DiffStatus::MISSING / DiffStatus::INVALID report the caller must return as-is.

searchAliasViewRecreate()

Drops and recreates a `search-alias` view to repair a drift — safe because the alias owns no data (the underlying inverted indexes survive).

private searchAliasViewRecreate(SearchAliasView $view) : bool
Parameters
$view : SearchAliasView

The declared search-alias view.

Tags
throws
ArangoException

When the drop or the recreate fails.

Return values
bool

Always TRUE (a failure surfaces as the thrown ArangoException).

On this page

Search results