From 57b1d4d795f1c3c54282ba7fdb95bfe0ee84bd61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:30:26 +0100 Subject: [PATCH] all but non-linear --- modules/ROOT/pages/patterns/fixed-length-patterns.adoc | 6 ++++++ modules/ROOT/pages/patterns/shortest-paths.adoc | 8 ++++++++ .../ROOT/pages/patterns/variable-length-patterns.adoc | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/modules/ROOT/pages/patterns/fixed-length-patterns.adoc b/modules/ROOT/pages/patterns/fixed-length-patterns.adoc index 96e66637c..d1ee7f13c 100644 --- a/modules/ROOT/pages/patterns/fixed-length-patterns.adoc +++ b/modules/ROOT/pages/patterns/fixed-length-patterns.adoc @@ -57,10 +57,14 @@ MATCH (n { mode: 'Rail' }) More general predicates can be expressed with a `WHERE` clause. The following matches nodes whose name property starts with `Preston`: +// tag::patterns_fixed_length_patterns_node_pattern[] [source, role=noheader] ---- MATCH (n:Station WHERE n.name STARTS WITH 'Preston') +RETURN n ---- +// end::patterns_fixed_length_patterns_node_pattern[] + See the xref:patterns/reference.adoc#node-patterns[node patterns] reference section for more details. @@ -204,11 +208,13 @@ In order to return the name of each `Stop` that calls at a `Station`, declare a The results will then have a row containing the departs value of each `Stop` for each match shown above: .Query +// tag::patterns_fixed_length_patterns_path_pattern[] [source, cypher] ---- MATCH (s:Stop)-[:CALLS_AT]->(: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_shortest_k[] [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_shortest_k[] .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"]