From 0a6fd917f1790a25163082c6d46d79bcdd1a10bb Mon Sep 17 00:00:00 2001 From: Richard Sill Date: Wed, 18 Dec 2024 11:35:26 +0100 Subject: [PATCH 1/9] tags for the FINISH clause --- modules/ROOT/pages/clauses/finish.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/ROOT/pages/clauses/finish.adoc b/modules/ROOT/pages/clauses/finish.adoc index b233b4896..a55dd9392 100644 --- a/modules/ROOT/pages/clauses/finish.adoc +++ b/modules/ROOT/pages/clauses/finish.adoc @@ -9,20 +9,24 @@ A query ending in `FINISH` — instead of `RETURN` — has no result but execute The following read query successfully executes but has no results: .Query +tag::clauses_finish_match[] [source, cypher] ---- MATCH (p:Person) FINISH ---- +end::clauses_finish_match[] The following query has no result but creates one node with the label `Person`: .Query +tag::clauses_finish_create[] [source, cypher] ---- CREATE (p:Person) FINISH ---- +end::clauses_finish_create[] It is equivalent to the following query: From f9594236afa768f9146620c4dbf013d42145cc45 Mon Sep 17 00:00:00 2001 From: Richard Sill Date: Wed, 18 Dec 2024 12:05:12 +0100 Subject: [PATCH 2/9] tags for the USE clause --- modules/ROOT/pages/clauses/finish.adoc | 2 +- modules/ROOT/pages/clauses/use.adoc | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/ROOT/pages/clauses/finish.adoc b/modules/ROOT/pages/clauses/finish.adoc index a55dd9392..816ae1665 100644 --- a/modules/ROOT/pages/clauses/finish.adoc +++ b/modules/ROOT/pages/clauses/finish.adoc @@ -3,7 +3,7 @@ [[query-finish]] = FINISH -A query ending in `FINISH` — instead of `RETURN` — has no result but executes all its side effects. +A query ending in `FINISH` -- instead of `RETURN` -- has no result but executes all its side effects. `FINISH` was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[]. The following read query successfully executes but has no results: diff --git a/modules/ROOT/pages/clauses/use.adoc b/modules/ROOT/pages/clauses/use.adoc index 1d5643469..a6045f548 100644 --- a/modules/ROOT/pages/clauses/use.adoc +++ b/modules/ROOT/pages/clauses/use.adoc @@ -68,14 +68,16 @@ CREATE ALIAS `myComposite`.`myConstituent` FOR DATABASE `myDatabase`; [[query-use-examples-query-graph]] === Query a graph -In this example it is assumed that the DBMS contains a database named `myDatabase`: +This example assumes that the DBMS contains a database named `myDatabase`: .Query +tag::clauses_use[] [source, cypher] ---- USE myDatabase MATCH (n) RETURN n ---- +end::clauses_use[] [[query-use-examples-query-composite-database-constituent-graph]] === Query a composite database constituent graph @@ -83,11 +85,13 @@ MATCH (n) RETURN n In this example it is assumed that the DBMS contains a composite database named `myComposite`, which includes an alias named `myConstituent`: .Query +tag::clauses_use_composite[] [source, cypher] ---- USE myComposite.myConstituent MATCH (n) RETURN n ---- +end::clauses_use_composite[] [[query-use-examples-query-composite-database-constituent-graph-dynamically]] From 943cf62b8996aea6b84f2c04de40e514b7f9dca7 Mon Sep 17 00:00:00 2001 From: Richard Sill Date: Wed, 18 Dec 2024 16:09:52 +0100 Subject: [PATCH 3/9] tags for ORDER BY, SKIP and UNWIND --- modules/ROOT/pages/clauses/order-by.adoc | 8 ++++++++ modules/ROOT/pages/clauses/skip.adoc | 6 ++++++ modules/ROOT/pages/clauses/unwind.adoc | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/modules/ROOT/pages/clauses/order-by.adoc b/modules/ROOT/pages/clauses/order-by.adoc index feb5bb766..c33e49b01 100644 --- a/modules/ROOT/pages/clauses/order-by.adoc +++ b/modules/ROOT/pages/clauses/order-by.adoc @@ -40,12 +40,14 @@ CREATE `ORDER BY` is used to sort the output. .Query +tag::clauses_order_by[] [source, cypher] ---- MATCH (n) RETURN n.name, n.age ORDER BY n.name ---- +end::clauses_order_by[] The nodes are returned, sorted by their name. @@ -67,12 +69,14 @@ You can order by multiple properties by stating each variable in the `ORDER BY` Cypher will sort the result by the first variable listed, and for equals values, go to the next property in the `ORDER BY` clause, and so on. .Query +tag::clauses_order_by_multiple[] [source, cypher] ---- MATCH (n) RETURN n.name, n.age ORDER BY n.age, n.name ---- +end::clauses_order_by_multiple[] This returns the nodes, sorted first by their age, and then by their name. @@ -246,12 +250,14 @@ Read more about this capability in xref::indexes/search-performance-indexes/usin .Standalone use of `ORDER BY` +tag::clauses_order_by_standalone[] [source, cypher] ---- MATCH (n) ORDER BY n.name RETURN collect(n.name) AS names ---- +end::clauses_order_by_standalone[] .Result [role="queryresult",options="header,footer",cols="1* Date: Thu, 19 Dec 2024 10:06:39 +0100 Subject: [PATCH 4/9] tags for LIMIT and FOREACH --- modules/ROOT/pages/clauses/foreach.adoc | 2 ++ modules/ROOT/pages/clauses/limit.adoc | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/modules/ROOT/pages/clauses/foreach.adoc b/modules/ROOT/pages/clauses/foreach.adoc index b594ecace..1f792bfc0 100644 --- a/modules/ROOT/pages/clauses/foreach.adoc +++ b/modules/ROOT/pages/clauses/foreach.adoc @@ -36,12 +36,14 @@ CREATE This query will set the property `marked` to `true` on all nodes along a path. .Query +tag::clauses_foreach[] [source, cypher, indent=0] ---- MATCH p=(start)-[*]->(finish) WHERE start.name = 'A' AND finish.name = 'D' FOREACH (n IN nodes(p) | SET n.marked = true) ---- +end::clauses_foreach[] .Result [role="queryresult",options="footer",cols="1* Date: Fri, 20 Dec 2024 10:00:26 +0100 Subject: [PATCH 5/9] escaped tags, added tags for LOAD CSV --- modules/ROOT/pages/clauses/finish.adoc | 8 ++++---- modules/ROOT/pages/clauses/foreach.adoc | 4 ++-- modules/ROOT/pages/clauses/limit.adoc | 8 ++++---- modules/ROOT/pages/clauses/load-csv.adoc | 16 +++++++++++++++- modules/ROOT/pages/clauses/order-by.adoc | 16 ++++++++-------- modules/ROOT/pages/clauses/skip.adoc | 12 ++++++------ modules/ROOT/pages/clauses/unwind.adoc | 12 ++++++------ modules/ROOT/pages/clauses/use.adoc | 8 ++++---- 8 files changed, 49 insertions(+), 35 deletions(-) diff --git a/modules/ROOT/pages/clauses/finish.adoc b/modules/ROOT/pages/clauses/finish.adoc index 816ae1665..27813a216 100644 --- a/modules/ROOT/pages/clauses/finish.adoc +++ b/modules/ROOT/pages/clauses/finish.adoc @@ -9,24 +9,24 @@ A query ending in `FINISH` -- instead of `RETURN` -- has no result but executes The following read query successfully executes but has no results: .Query -tag::clauses_finish_match[] +// tag::clauses_finish_match[] [source, cypher] ---- MATCH (p:Person) FINISH ---- -end::clauses_finish_match[] +// end::clauses_finish_match[] The following query has no result but creates one node with the label `Person`: .Query -tag::clauses_finish_create[] +// tag::clauses_finish_create[] [source, cypher] ---- CREATE (p:Person) FINISH ---- -end::clauses_finish_create[] +// end::clauses_finish_create[] It is equivalent to the following query: diff --git a/modules/ROOT/pages/clauses/foreach.adoc b/modules/ROOT/pages/clauses/foreach.adoc index 1f792bfc0..b9678fb2e 100644 --- a/modules/ROOT/pages/clauses/foreach.adoc +++ b/modules/ROOT/pages/clauses/foreach.adoc @@ -36,14 +36,14 @@ CREATE This query will set the property `marked` to `true` on all nodes along a path. .Query -tag::clauses_foreach[] +// tag::clauses_foreach[] [source, cypher, indent=0] ---- MATCH p=(start)-[*]->(finish) WHERE start.name = 'A' AND finish.name = 'D' FOREACH (n IN nodes(p) | SET n.marked = true) ---- -end::clauses_foreach[] +// end::clauses_foreach[] .Result [role="queryresult",options="footer",cols="1* Date: Wed, 8 Jan 2025 11:43:23 +0100 Subject: [PATCH 6/9] added two examples to the FOREACH page --- modules/ROOT/pages/clauses/foreach.adoc | 41 +++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/modules/ROOT/pages/clauses/foreach.adoc b/modules/ROOT/pages/clauses/foreach.adoc index b9678fb2e..1f595a1cb 100644 --- a/modules/ROOT/pages/clauses/foreach.adoc +++ b/modules/ROOT/pages/clauses/foreach.adoc @@ -33,17 +33,17 @@ CREATE [[foreach-mark-all-nodes-along-a-path]] == Mark all nodes along a path -This query will set the property `marked` to `true` on all nodes along a path. +This query sets the property `marked` to `true` on all nodes along a path. .Query -// tag::clauses_foreach[] +// tag::clauses_foreach_node[] [source, cypher, indent=0] ---- MATCH p=(start)-[*]->(finish) WHERE start.name = 'A' AND finish.name = 'D' FOREACH (n IN nodes(p) | SET n.marked = true) ---- -// end::clauses_foreach[] +// end::clauses_foreach_node[] .Result [role="queryresult",options="footer",cols="1*(finish) +WHERE start.name = 'A' AND finish.name = 'D' +FOREACH ( r IN relationships(p) | SET r.marked = true ) +---- +// end::clauses_foreach_relationship[] + +.Result +[role="queryresult",options="footer",cols="1* Date: Wed, 8 Jan 2025 13:03:16 +0100 Subject: [PATCH 7/9] added custom section anchors and result listings --- modules/ROOT/pages/clauses/foreach.adoc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/ROOT/pages/clauses/foreach.adoc b/modules/ROOT/pages/clauses/foreach.adoc index 1f595a1cb..237ea086a 100644 --- a/modules/ROOT/pages/clauses/foreach.adoc +++ b/modules/ROOT/pages/clauses/foreach.adoc @@ -54,6 +54,7 @@ Properties set: 4 |=== +[[foreach-mark-all-relationships-along-a-path]] == Mark all relationships along a path This query sets the property `marked` to `true` on all relationships along a path. @@ -72,10 +73,10 @@ FOREACH ( r IN relationships(p) | SET r.marked = true ) |=== |(empty result) d|Rows: 0 + -Properties set: 4 +Properties set: 3 |=== - +[[foreach-create-new-nodes-form-a-list]] == Create new nodes from a list of name labels This query creates a new node for each label in a list. @@ -87,4 +88,12 @@ This query creates a new node for each label in a list. WITH ['E', 'F', 'G'] AS names FOREACH ( value IN names | CREATE (:Person {name: value}) ) ---- -// end::clauses_foreach_create[] \ No newline at end of file +// end::clauses_foreach_create[] + +.Result +[role="queryresult",options="footer",cols="1* Date: Tue, 14 Jan 2025 09:31:43 +0100 Subject: [PATCH 8/9] Apply suggestions from code review --- modules/ROOT/pages/clauses/foreach.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ROOT/pages/clauses/foreach.adoc b/modules/ROOT/pages/clauses/foreach.adoc index 237ea086a..2132954e6 100644 --- a/modules/ROOT/pages/clauses/foreach.adoc +++ b/modules/ROOT/pages/clauses/foreach.adoc @@ -60,7 +60,7 @@ Properties set: 4 This query sets the property `marked` to `true` on all relationships along a path. // tag::clauses_foreach_relationship[] -[source, cypher, indent=0, role=test-skip] +[source, cypher, indent=0] ---- MATCH p=(start)-[*]->(finish) WHERE start.name = 'A' AND finish.name = 'D' @@ -83,7 +83,7 @@ This query creates a new node for each label in a list. .Query // tag::clauses_foreach_create[] -[source, cypher, indent=0 role=test-skip] +[source, cypher, indent=0] ---- WITH ['E', 'F', 'G'] AS names FOREACH ( value IN names | CREATE (:Person {name: value}) ) From 385cfeb94b48111a91577ab45f822344f688db75 Mon Sep 17 00:00:00 2001 From: Richard Sill <156673635+rsill-neo4j@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:11:38 +0100 Subject: [PATCH 9/9] Apply suggestions from code review --- modules/ROOT/pages/clauses/finish.adoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/ROOT/pages/clauses/finish.adoc b/modules/ROOT/pages/clauses/finish.adoc index 27813a216..2d3315e13 100644 --- a/modules/ROOT/pages/clauses/finish.adoc +++ b/modules/ROOT/pages/clauses/finish.adoc @@ -20,13 +20,11 @@ FINISH The following query has no result but creates one node with the label `Person`: .Query -// tag::clauses_finish_create[] [source, cypher] ---- CREATE (p:Person) FINISH ---- -// end::clauses_finish_create[] It is equivalent to the following query: