Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/ROOT/pages/patterns/match-modes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ To show the behavior of `DIFFERENT RELATIONSHIPS`, consider the following query,
The relationships used in this query are directional, meaning paths are traversed following specific directions for each bridge (`-[:BRIDGE]\->`).

.Find paths with a length of 5 relationships from a start node
// tag::patterns_match_modes_different_relationships[]
[source, cypher]
----
MATCH p = (:Location {name: 'Kneiphof'})-[:BRIDGE]->{5}()
RETURN [n IN nodes(p) | n.name] AS locations,
[r IN relationships(p) | r.id] AS crossedBridges // <1>
----
// end::patterns_match_modes_different_relationships[]

<1> The xref:expressions/list-expressions.adoc#list-comprehension[list comprehensions] iterate over nodes and relationships in a path and return specific properties (the `name` property from nodes, and the `id` property from relationships).

Expand Down Expand Up @@ -153,13 +155,15 @@ Queries utilizing this match mode must specify the `REPEATABLE ELEMENTS` keyword
The following query matches the graph for paths with a length of `7` relationships using `REPEATABLE ELEMENTS` and returns a sample path.

.Find a path with a length of 7 relationships using `REPEATABLE ELEMENTS`
// tag::patterns_match_modes_repeatable_elements[]
[source, cypher]
----
MATCH REPEATABLE ELEMENTS p = (:Location {name: 'Kneiphof'})-[:BRIDGE]-{7}()
WITH collect(p)[0] AS samplePath
RETURN [n IN nodes(samplePath) | n.name] AS samplePathLocations,
[r IN relationships(samplePath) | r.id] AS samplePathBridges
----
// end::patterns_match_modes_repeatable_elements[]

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ RETURN customer.firstName AS chocolateCustomer


.Passing multiple variables to another query via `NEXT`
// tag::sequential_queries_basic_example[]
[source, cypher]
----
MATCH (c:Customer)-[:BUYS]->(p:Product {name: 'Chocolate'})
Expand All @@ -119,6 +120,7 @@ NEXT
RETURN customer.firstName AS chocolateCustomer,
product.price * (1 - customer.discount) AS chocolatePrice
----
// end::sequential_queries_basic_example[]

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down Expand Up @@ -162,6 +164,8 @@ RETURN p.name as product, customers
======
[.include-with-NEXT]
======

// tag::sequential_queries_call[]
[source, cypher]
----
MATCH (p:Product)
Expand All @@ -176,6 +180,7 @@ NEXT

RETURN p.name as product, customers
----
// end::sequential_queries_next_call[]
======
====

Expand Down Expand Up @@ -204,6 +209,7 @@ It also avoids the parentheses and indentation of the `CALL` subquery.
== Interactions with conditional queries

.Conditional queries in `NEXT`
// tag::sequential_queries_chaining_conditional_queries[]
[source, cypher]
----
MATCH (c:Customer)-[:BUYS]->(:Product)<-[:SUPPLIES]-(s:Supplier)
Expand All @@ -227,6 +233,7 @@ WHEN size(personalities) > 1 THEN
ELSE
RETURN customer, personalities[0] AS personality
----
// end::sequential_queries_chaining_conditional_queries[]

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
Expand Down Expand Up @@ -255,6 +262,7 @@ Finally, the fourth segment is another conditional query which subsumes multiple
If a conditional query has a `NEXT` in any of its `THEN` or `ELSE` blocks, it is necessary to wrap the part after `THEN` or `ELSE` with `{}`.

.`NEXT` inside a conditional query
// tag::sequential_queries_in_conditional_queries[]
[source, cypher]
----
MATCH (c:Customer)-[:BUYS]->(p:Product)
Expand All @@ -273,6 +281,7 @@ ELSE {
RETURN customer.firstName AS customer, "club below 1000" AS customerType, finalSum AS sum
}
----
// end::sequential_queries_in_conditional_queries[]

.Result
[role="queryresult",options="header,footer",cols="3*<m"]
Expand Down