-
Notifications
You must be signed in to change notification settings - Fork 5
MATCH clause
Marijn van Wezel edited this page Dec 9, 2022
·
8 revisions
The MATCH
clause is used to search for the pattern described in it. It accepts a list of patterns to match on.
Query::match(CompletePattern|CompletePattern[] $patterns): Query
-
$patterns
: The patterns to match on.
$n = Query::node();
$query = Query::new()
->match($n)
->returning($n)
->build();
$this->assertStringMatchesFormat("MATCH (%s) RETURN %s", $query);
$movie = Query::node("Movie");
$query = Query::new()
->match($movie)
->returning($movie->property("title"))
->build();
$this->assertStringMatchesFormat("MATCH (%s:Movie) RETURN %s.title", $query);
$movie = Query::node();
$query = Query::new()
->match(Query::node()->withProperties(['name' => 'Oliver Stone'])->relationshipUni($movie))
->returning($movie->property("title"))
->build();
$this->assertStringMatchesFormat("MATCH ({name: 'Oliver Stone'})--(%s) RETURN %s.title", $query);
$movie = Query::node('Movie');
$query = Query::new()
->match(Query::node('Person')->withProperties(['name' => 'Oliver Stone'])->relationshipUni($movie))
->returning($movie->property("title"))
->build();
$this->assertStringMatchesFormat("MATCH (:Person {name: 'Oliver Stone'})--(%s:Movie) RETURN %s.title", $query);
The more complex label expression syntax added in Neo4j 5.0 is not yet supported.
$n = Query::node()->addLabel('Movie', 'Person');
$query = Query::new()
->match($n)
->returning(['name' => $n->property("name"), 'title' => $n->property("title")])
->build();
$this->assertStringMatchesFormat("MATCH (%s:Movie:Person) RETURN %s.name AS name, %s.title AS title", $query);