diff --git a/modules/ROOT/pages/clauses/match.adoc b/modules/ROOT/pages/clauses/match.adoc index 300225568..bc81ff811 100644 --- a/modules/ROOT/pages/clauses/match.adoc +++ b/modules/ROOT/pages/clauses/match.adoc @@ -90,11 +90,14 @@ RETURN movie.title === MATCH using node label expressions .Node pattern using the `OR` (`|`) label expression +// tag::clauses_match_label_expression_or[] [source, cypher] ---- MATCH (n:Movie|Person) RETURN n.name AS name, n.title AS title ---- +// end::clauses_match_label_expression_or[] + .Result [role="queryresult",options="header,footer",cols="2*(:Station {name: 'Denmark Hill'}) RETURN s.departs AS departureTime ---- +// end::patterns_fixed_length_patterns_path_pattern[] .Result [role="queryresult",options="header,footer",cols="1*` on the relationship pattern, allowing the pattern to match relationships going in either direction. This represents the fact that trains can go in both directions along the `LINK` relationships between Stations. The `+` quantifier means that one or more relationships should be matched. For more information, see xref:patterns/reference.adoc#quantified-relationships[Syntax and semantics - quantified relationships]. @@ -157,12 +159,14 @@ If there had been only four possible paths between the two Stations, then only t To return all paths that are tied for shortest length, use the keywords `ALL SHORTEST`: .Query +// tag::patterns_shortest_paths_all_shortest[] [source,cypher] ---- MATCH p = ALL SHORTEST (wos:Station)-[:LINK]-+(bmv:Station) WHERE wos.name = "Worcester Shrub Hill" AND bmv.name = "Bromsgrove" RETURN [n in nodes(p) | n.name] AS stops ---- +// end::patterns_shortest_paths_all_shortest[] .Result [role="queryresult",options="header,footer",cols="m"] @@ -184,12 +188,14 @@ To return all paths that are tied for first, second, and so on up to the kth sho For example, the following returns the first and second shortest length paths between `Worcester Shrub Hill` and `Bromsgrove`: .Query +// tag::patterns_shortest_paths_shortest_k_groups[] [source,cypher] ---- MATCH p = SHORTEST 2 GROUPS (wos:Station)-[:LINK]-+(bmv:Station) WHERE wos.name = "Worcester Shrub Hill" AND bmv.name = "Bromsgrove" RETURN [n in nodes(p) | n.name] AS stops, length(p) AS pathLength ---- +// end::patterns_shortest_paths_shortest_k_groups[] .Result [role="queryresult",options="header,footer",cols="2m,m"] @@ -240,12 +246,14 @@ It returns the same as `SHORTEST 1`, but by using the `ANY` keyword the intent o For example, the following query shows that there exists a route from `Pershore` to `Bromsgrove` where the distance between each pair of stations is less than 10 miles: .Query +// tag::patterns_shortest_paths_any[] [source,cypher] ---- MATCH path = ANY (:Station {name: 'Pershore'})-[l:LINK WHERE l.distance < 10]-+(b:Station {name: 'Bromsgrove'}) RETURN [r IN relationships(path) | r.distance] AS distances ---- +// end::patterns_shortest_paths_any[] .Result [role="queryresult",options="header,footer",cols="m"] diff --git a/modules/ROOT/pages/patterns/variable-length-patterns.adoc b/modules/ROOT/pages/patterns/variable-length-patterns.adoc index 89041e57a..927c6220b 100644 --- a/modules/ROOT/pages/patterns/variable-length-patterns.adoc +++ b/modules/ROOT/pages/patterns/variable-length-patterns.adoc @@ -172,6 +172,7 @@ Translating the union of fixed-length path patterns into a quantified path patte The following query adds a `RETURN` clause that yields the departure and arrival times of the two services: .Query +// tag::patterns_variable_length_patterns_qpp[] [source, cypher] ---- MATCH (:Station { name: 'Denmark Hill' })<-[:CALLS_AT]-(d:Stop) @@ -179,6 +180,8 @@ MATCH (:Station { name: 'Denmark Hill' })<-[:CALLS_AT]-(d:Stop) (a:Stop)-[:CALLS_AT]->(:Station { name: 'Clapham Junction' }) RETURN d.departs AS departureTime, a.arrives AS arrivalTime ---- +// end::patterns_variable_length_patterns_qpp[] + .Result [role="queryresult",options="header,footer",cols="2*` and not the node patterns abutting it. More generally, where a path pattern contained in a quantified path pattern has the following form: @@ -523,6 +529,7 @@ In this example, an inline predicate can be added that takes advantage of the ge To compose the predicate, the xref:functions/spatial.adoc#functions-distance[point.distance()] function is used to compare the distance between the left-hand `Station` (`a`) and the right-hand `Station` (`b`) for each node-pair along the path to the destination `North Dulwich`: .Query +// tag::patterns_variable_length_patterns_predicates_in_qpp[] [source,cypher] ---- MATCH (bfr:Station {name: "London Blackfriars"}), @@ -534,6 +541,8 @@ MATCH p = (bfr) RETURN reduce(acc = 0, r in relationships(p) | round(acc + r.distance, 2)) AS distance ---- +// end::patterns_variable_length_patterns_predicates_in_qpp[] + .Result [role="queryresult",options="header,footer",cols="m"]