Oihana PHP Arango

phrase.php

Table of Contents

Functions

phrase()  : string
Match documents containing a phrase — tokens in the given order.

Functions

phrase()

Match documents containing a phrase — tokens in the given order.

phrase(string $path, string|array<string|int, mixed> $phrase[, string|null $analyzer = null ]) : string

Wraps the ArangoDB AQL function PHRASE(path, phrasePart, analyzer). The phrase can be:

  • a string — the simple form, emitted as a quoted string literal;
  • an array — the advanced AQL array form, emitted with json_encode, mirroring the official syntax one-to-one: string tokens are quoted, integers act as skipTokens wildcards, and associative arrays become object tokens ({IN_RANGE: …}, {LEVENSHTEIN_MATCH: …}, {STARTS_WITH: …}, {TERM: …}, {TERMS: …}, {WILDCARD: …}).

The Analyzer must have the "position" and "frequency" features enabled, otherwise PHRASE() finds nothing. When $analyzer is omitted, the Analyzer of a wrapping analyzer() call applies (default "identity").

Example AQL usage:

PHRASE(doc.text, "quick fox", "text_en")
PHRASE(doc.text, ["ipsum", 2, "amet"], "text_en")              // 2 wildcard tokens between
PHRASE(doc.text, ["lorem", {STARTS_WITH: ["ips"]}], "text_en") // prefix object token
Parameters
$path : string

Attribute path expression to test (kept raw).

$phrase : string|array<string|int, mixed>

The phrase: a plain string, or the AQL array form (tokens, skipTokens numbers, object tokens).

$analyzer : string|null = null

Optional Analyzer name (emitted as a quoted string literal).

Tags
example
use function oihana\arango\db\functions\search\phrase;

echo phrase( 'doc.text' , 'quick fox' , 'text_en' ) ;
// 'PHRASE(doc.text,"quick fox","text_en")'

echo phrase( 'doc.text' , [ 'ipsum' , 2 , 'amet' ] , 'text_en' ) ;
// 'PHRASE(doc.text,["ipsum",2,"amet"],"text_en")'

echo phrase( 'doc.text' , [ 'lorem' , [ 'STARTS_WITH' => [ 'ips' ] ] ] , 'text_en' ) ;
// 'PHRASE(doc.text,["lorem",{"STARTS_WITH":["ips"]}],"text_en")'
see
https://docs.arangodb.com/stable/aql/functions/arangosearch/#phrase
analyzer()
since
1.2.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results