Skip to content

Commit 81c4b62

Browse files
authored
Apply tags for clause and read query to 5.x (#1161)
1 parent 6ff579a commit 81c4b62

File tree

14 files changed

+146
-4
lines changed

14 files changed

+146
-4
lines changed

modules/ROOT/pages/clauses/finish.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
[[query-finish]]
44
= FINISH
55

6-
A query ending in `FINISH` instead of `RETURN` has no result but executes all its side effects.
6+
A query ending in `FINISH` -- instead of `RETURN` -- has no result but executes all its side effects.
77
`FINISH` was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[].
88

99
The following read query successfully executes but has no results:
1010

1111
.Query
12+
// tag::clauses_finish_match[]
1213
[source, cypher]
1314
----
1415
MATCH (p:Person)
1516
FINISH
1617
----
18+
// end::clauses_finish_match[]
1719

1820
The following query has no result but creates one node with the label `Person`:
1921

modules/ROOT/pages/clauses/foreach.adoc

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ CREATE
3333
[[foreach-mark-all-nodes-along-a-path]]
3434
== Mark all nodes along a path
3535

36-
This query will set the property `marked` to `true` on all nodes along a path.
36+
This query sets the property `marked` to `true` on all nodes along a path.
3737

3838
.Query
39+
// tag::clauses_foreach_node[]
3940
[source, cypher, indent=0]
4041
----
4142
MATCH p=(start)-[*]->(finish)
4243
WHERE start.name = 'A' AND finish.name = 'D'
4344
FOREACH (n IN nodes(p) | SET n.marked = true)
4445
----
46+
// end::clauses_foreach_node[]
4547

4648
.Result
4749
[role="queryresult",options="footer",cols="1*<m"]
@@ -51,3 +53,47 @@ d|Rows: 0 +
5153
Properties set: 4
5254
|===
5355

56+
57+
[[foreach-mark-all-relationships-along-a-path]]
58+
== Mark all relationships along a path
59+
60+
This query sets the property `marked` to `true` on all relationships along a path.
61+
62+
// tag::clauses_foreach_relationship[]
63+
[source, cypher, indent=0]
64+
----
65+
MATCH p=(start)-[*]->(finish)
66+
WHERE start.name = 'A' AND finish.name = 'D'
67+
FOREACH ( r IN relationships(p) | SET r.marked = true )
68+
----
69+
// end::clauses_foreach_relationship[]
70+
71+
.Result
72+
[role="queryresult",options="footer",cols="1*<m"]
73+
|===
74+
|(empty result)
75+
d|Rows: 0 +
76+
Properties set: 3
77+
|===
78+
79+
[[foreach-create-new-nodes-form-a-list]]
80+
== Create new nodes from a list of name labels
81+
82+
This query creates a new node for each label in a list.
83+
84+
.Query
85+
// tag::clauses_foreach_create[]
86+
[source, cypher, indent=0]
87+
----
88+
WITH ['E', 'F', 'G'] AS names
89+
FOREACH ( value IN names | CREATE (:Person {name: value}) )
90+
----
91+
// end::clauses_foreach_create[]
92+
93+
.Result
94+
[role="queryresult",options="footer",cols="1*<m"]
95+
|===
96+
1+|(empty result)
97+
1+d|Rows: 0 +
98+
Nodes created: 3
99+
|===

modules/ROOT/pages/clauses/limit.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,14 @@ Properties set: 1
166166
`LIMIT` can be used as a standalone clause, or in conjunction with xref:clauses/order-by.adoc[`ORDER BY`] or xref:clauses/skip.adoc[`SKIP`]/xref:clauses/skip.adoc#offset-synonym[`OFFSET`].
167167

168168
.Standalone use of `LIMIT`
169+
// tag::clauses_limit_standalone[]
169170
[source, cypher]
170171
----
171172
MATCH (n)
172173
LIMIT 2
173174
RETURN collect(n.name) AS names
174175
----
176+
// end::clauses_limit_standalone[]
175177

176178
.Result
177179
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -185,6 +187,7 @@ The following query orders all nodes by `name` descending, skips the two first r
185187
It then xref:functions/aggregating.adoc#functions-collect[collects] the results in a list.
186188

187189
.`LIMIT` used in conjunction with `ORDER BY` and `SKIP`
190+
// tag::clauses_limit[]
188191
[source, cypher]
189192
----
190193
MATCH (n)
@@ -193,6 +196,7 @@ SKIP 2
193196
LIMIT 2
194197
RETURN collect(n.name) AS names
195198
----
199+
// end::clauses_limit[]
196200

197201
.Result
198202
[role="queryresult",options="header,footer",cols="1*<m"]

modules/ROOT/pages/clauses/load-csv.adoc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ By default, paths are resolved relative to the Neo4j import directory.
4646
----
4747
4848
.Query
49+
// tag::clauses_load_csv_local_files[]
4950
[source, cypher]
5051
----
5152
LOAD CSV FROM 'file:///artists.csv' AS row
5253
MERGE (a:Artist {name: row[1], year: toInteger(row[2])})
5354
RETURN a.name, a.year
5455
----
56+
// end::clauses_load_csv_local_files[]
5557
5658
.Result
5759
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -112,12 +114,14 @@ However, this means that insecure URLs on virtual hosts will not function unless
112114
----
113115
114116
.Query
117+
// tag::clauses_load_csv_remote_locations[]
115118
[source, cypher]
116119
----
117120
LOAD CSV FROM 'https://data.neo4j.com/bands/artists.csv' AS row
118121
MERGE (a:Artist {name: row[1], year: toInteger(row[2])})
119122
RETURN a.name, a.year
120123
----
124+
// end::clauses_load_csv_remote_locations[]
121125
122126
.Result
123127
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -705,10 +709,11 @@ person_tmdbId,bio,born,bornIn,died,person_imdbId,name,person_poster,person_url
705709
----
706710
707711
[NOTE]
708-
The below query uses a xref:subqueries/call-subquery.adoc#variable-scope-clause[variable scope clause] (introduced in Neo4j 5.23) to import variables into the `CALL` subquery.
712+
The query below uses a xref:subqueries/call-subquery.adoc#variable-scope-clause[variable scope clause] (introduced in Neo4j 5.23) to import variables into the `CALL` subquery.
709713
If you are using an older version of Neo4j, use an xref:subqueries/call-subquery.adoc#importing-with[importing `WITH` clause] instead.
710714
711715
.Query
716+
// tag::clauses_load_csv_transactions[]
712717
[source, cypher]
713718
----
714719
LOAD CSV WITH HEADERS FROM 'https://data.neo4j.com/importing-cypher/persons.csv' AS row
@@ -717,6 +722,7 @@ CALL (row) {
717722
SET p.name = row.name, p.born = row.born
718723
} IN TRANSACTIONS OF 200 ROWS
719724
----
725+
// end::clauses_load_csv_transactions[]
720726
721727
.Result
722728
[source, role="queryresult"]
@@ -751,11 +757,13 @@ A common use case for this function is to generate sequential unique IDs for CSV
751757
----
752758
753759
.Query
760+
// tag::clauses_load_csv_linenumber[]
754761
[source, cypher]
755762
----
756763
LOAD CSV FROM 'file:///artists.csv' AS row
757764
RETURN linenumber() AS number, row
758765
----
766+
// end::clauses_load_csv_linenumber[]
759767
760768
.Result
761769
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -786,11 +794,13 @@ The xref:functions/load-csv.adoc#functions-file[`file()`] function provides the
786794
----
787795
788796
.Query
797+
// tag::clauses_load_csv_file[]
789798
[source, cypher, role=test-result-skip]
790799
----
791800
LOAD CSV FROM 'file:///artists.csv' AS row
792801
RETURN DISTINCT file() AS path
793802
----
803+
// end::clauses_load_csv_file[]
794804
795805
.Result
796806
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -837,6 +847,7 @@ Id,Name,Year
837847
----
838848
839849
.Query
850+
// tag::clauses_load_csv_headers[]
840851
[source, cypher]
841852
----
842853
LOAD CSV WITH HEADERS FROM 'file:///artists-with-headers.csv' AS row
@@ -845,6 +856,7 @@ RETURN
845856
a.name AS name,
846857
a.year AS year
847858
----
859+
// end::clauses_load_csv_headers[]
848860
849861
.Result
850862
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -880,11 +892,13 @@ If you try to import a file that doesn't use `,` as field delimiter and you also
880892
----
881893
882894
.Query
895+
// tag::clauses_load_csv_field_terminator[]
883896
[source, cypher]
884897
----
885898
LOAD CSV FROM 'file:///artists-fieldterminator.csv' AS row FIELDTERMINATOR ';'
886899
MERGE (:Artist {name: row[1], year: toInteger(row[2])})
887900
----
901+
// end::clauses_load_csv_field_terminator[]
888902
889903
.Result
890904
[source, role="queryresult"]

modules/ROOT/pages/clauses/match.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ For more information about finding node patterns, see xref:patterns/fixed-length
4545
By specifying a pattern with a single node and no labels, all nodes in the graph will be returned.
4646

4747
.Find all nodes in a graph
48+
// tag::clauses_match_all_nodes[]
4849
[source, cypher]
4950
----
5051
MATCH (n)
5152
RETURN n
5253
----
54+
// end::clauses_match_all_nodes[]
5355

5456
.Result
5557
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -70,11 +72,13 @@ RETURN n
7072
=== Find nodes with a specific label
7173

7274
.Find all nodes with the `Movie` label
75+
// tag::clauses_match_label[]
7376
[source, cypher]
7477
----
7578
MATCH (movie:Movie)
7679
RETURN movie.title
7780
----
81+
// end::clauses_match_label[]
7882

7983
.Result
8084
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -195,11 +199,13 @@ RETURN movie.title AS movieTitle
195199
It is possible to introduce a variable to a pattern, either for filtering on relationship properties or to return a relationship.
196200

197201
.Find the types of an aliased relationship
202+
// tag::clauses_match_relationship_types[]
198203
[source, cypher]
199204
----
200205
MATCH (:Person {name: 'Oliver Stone'})-[r]->()
201206
RETURN type(r) AS relType
202207
----
208+
// end::clauses_match_relationship_types[]
203209

204210
[NOTE]
205211
The above query uses the xref:functions/scalar.adoc#functions-type[`type()` function].
@@ -244,11 +250,13 @@ RETURN a, b
244250
It is possible to specify the type of a relationship in a relationship pattern by using a colon (`:`) before the relationship type.
245251

246252
.Relationship pattern filtering on the `ACTED_IN` relationship type
253+
// tag::clauses_match_relationship[]
247254
[source, cypher]
248255
----
249256
MATCH (:Movie {title: 'Wall Street'})<-[:ACTED_IN]-(actor:Person)
250257
RETURN actor.name AS actor
251258
----
259+
// end::clauses_match_relationship[]
252260

253261
.Result
254262
[source, role="queryresult",options="header,footer",cols="1*<m"]
@@ -400,11 +408,13 @@ For more information about how to set parameters, see xref:syntax/parameters.ado
400408
The `MATCH` clause can also be used to bind whole paths to variables.
401409

402410
.Find all paths matching a pattern
411+
// tag::clauses_match_path[]
403412
[source, cypher]
404413
----
405414
MATCH path = ()-[:ACTED_IN]->(movie:Movie)
406415
RETURN path
407416
----
417+
// end::clauses_match_path[]
408418

409419
.Result
410420
[role="queryresult",options="header,footer",cols="1*<m"]

modules/ROOT/pages/clauses/optional-match.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ This is because the second `MATCH` clause returns no data (there are no `DIRECTE
7979
However, replacing the second `MATCH` clause with `OPTIONAL MATCH` does return results.
8080
This is because, unlike `MATCH`, `OPTIONAL MATCH` enables the value `null` to be passed between clauses.
8181

82+
// tag::clauses_optional_match[]
8283
[source, cypher]
8384
----
8485
MATCH (p:Person {name: 'Martin Sheen'})
8586
OPTIONAL MATCH (p)-[r:DIRECTED]->()
8687
RETURN p.name, r
8788
----
89+
// end::clauses_optional_match[]
8890

8991
.Result
9092
[role="queryresult",options="header,footer",cols="2*<m"]

modules/ROOT/pages/clauses/order-by.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ CREATE
4040
`ORDER BY` is used to sort the output.
4141

4242
.Query
43+
// tag::clauses_order_by[]
4344
[source, cypher]
4445
----
4546
MATCH (n)
4647
RETURN n.name, n.age
4748
ORDER BY n.name
4849
----
50+
// end::clauses_order_by[]
4951

5052
The nodes are returned, sorted by their name.
5153

@@ -67,12 +69,14 @@ You can order by multiple properties by stating each variable in the `ORDER BY`
6769
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.
6870

6971
.Query
72+
// tag::clauses_order_by_multiple[]
7073
[source, cypher]
7174
----
7275
MATCH (n)
7376
RETURN n.name, n.age
7477
ORDER BY n.age, n.name
7578
----
79+
// end::clauses_order_by_multiple[]
7680

7781
This returns the nodes, sorted first by their age, and then by their name.
7882

@@ -246,12 +250,14 @@ Read more about this capability in xref::indexes/search-performance-indexes/usin
246250

247251

248252
.Standalone use of `ORDER BY`
253+
// tag::clauses_order_by_standalone[]
249254
[source, cypher]
250255
----
251256
MATCH (n)
252257
ORDER BY n.name
253258
RETURN collect(n.name) AS names
254259
----
260+
// end::clauses_order_by_standalone[]
255261

256262
.Result
257263
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -264,6 +270,7 @@ RETURN collect(n.name) AS names
264270
The following query orders all nodes by `name` descending, skips the first row and limits the results to one row.
265271

266272
.`ORDER BY` used in conjunction with `SKIP` and `LIMIT`
273+
// tag::clauses_order_by_descending[]
267274
[source, cypher]
268275
----
269276
MATCH (n)
@@ -272,6 +279,7 @@ SKIP 1
272279
LIMIT 1
273280
RETURN n.name AS name
274281
----
282+
// end::clauses_order_by_descending[]
275283

276284
.Result
277285
[role="queryresult",options="header,footer",cols="1*<m"]

0 commit comments

Comments
 (0)