diff --git a/modules/ROOT/pages/functions/aggregating.adoc b/modules/ROOT/pages/functions/aggregating.adoc index 2976c3666..76ae6984c 100644 --- a/modules/ROOT/pages/functions/aggregating.adoc +++ b/modules/ROOT/pages/functions/aggregating.adoc @@ -63,11 +63,13 @@ CREATE ====== .Query +// tag::functions_aggregating_avg[] [source, cypher] ---- MATCH (p:Person) RETURN avg(p.age) ---- +// end::functions_aggregating_avg[] The average of all the values in the property `age` is returned: @@ -87,11 +89,13 @@ The average of all the values in the property `age` is returned: ====== .Query +// tag::functions_aggregating_duration_avg[] [source, cypher] ---- UNWIND [duration('P2DT3H'), duration('PT1H45S')] AS dur RETURN avg(dur) ---- +// end::functions_aggregating_duration_avg[] The average of the two supplied `DURATION` values is returned: @@ -133,11 +137,13 @@ The average of the two supplied `DURATION` values is returned: ====== .Query +// tag::functions_aggregating_collect[] [source, cypher] ---- MATCH (p:Person) RETURN collect(p.age) ---- +// end::functions_aggregating_collect[] All the values are collected and returned in a single list: @@ -189,11 +195,13 @@ The function `count(*)` can be used to return the number of nodes; for example, ====== .Query +// tag::functions_aggregating_count[] [source, cypher] ---- MATCH (p:Person {name: 'Keanu Reeves'})-->(x) RETURN labels(p), p.age, count(*) ---- +// end::functions_aggregating_count[] The labels and `age` property of the start node `Keanu Reeves` and the number of nodes related to it are returned: @@ -248,11 +256,13 @@ Instead of simply returning the number of rows with `count(*)`, the function `co ====== .Query +// tag::functions_aggregating_count_as_expression[] [source, cypher] ---- MATCH (p:Person) RETURN count(p.age) ---- +// end::functions_aggregating_count_as_expression[] The number of nodes with the label `Person` and a property `age` is returned: (To calculate the sum, use `sum(n.age)`) @@ -389,11 +399,13 @@ The highest of all the lists in the set -- in this case, the list `[1, 2]` -- is ====== .Query +// tag::functions_aggregating_max[] [source, cypher] ---- MATCH (p:Person) RETURN max(p.age) ---- +// end::functions_aggregating_max[] The highest of all the values in the property `age` is returned: @@ -486,11 +498,13 @@ The lowest of all the values in the set -- in this case, the list `['a', 'c', 23 ====== .Query +// tag::functions_aggregating_min[] [source, cypher] ---- MATCH (p:Person) RETURN min(p.age) ---- +// end::functions_aggregating_min[] The lowest of all the values in the property `age` is returned: @@ -532,11 +546,13 @@ The lowest of all the values in the property `age` is returned: ====== .Query +// tag::functions_aggregating_percentile_cont[] [source, cypher] ---- MATCH (p:Person) RETURN percentileCont(p.age, 0.4) ---- +// end::functions_aggregating_percentile_cont[] The 40th percentile of the values in the property `age` is returned, calculated with a weighted average: @@ -579,11 +595,13 @@ The 40th percentile of the values in the property `age` is returned, calculated ====== .Query +// tag::functions_aggregating_percentile_disc[] [source, cypher] ---- MATCH (p:Person) RETURN percentileDisc(p.age, 0.5) ---- +// end::functions_aggregating_percentile_disc[] The 50th percentile of the values in the property `age` is returned: @@ -625,12 +643,14 @@ The 50th percentile of the values in the property `age` is returned: ====== .Query +// tag::functions_aggregating_stdev[] [source, cypher] ---- MATCH (p:Person) WHERE p.name IN ['Keanu Reeves', 'Liam Neeson', 'Carrie Anne Moss'] RETURN stDev(p.age) ---- +// end::functions_aggregating_stdev[] The standard deviation of the values in the property `age` is returned: @@ -672,12 +692,14 @@ The standard deviation of the values in the property `age` is returned: ====== .Query +// tag::functions_aggregating_stdevp[] [source, cypher] ---- MATCH (p:Person) WHERE p.name IN ['Keanu Reeves', 'Liam Neeson', 'Carrie Anne Moss'] RETURN stDevP(p.age) ---- +// end::functions_aggregating_stdevp[] The population standard deviation of the values in the property `age` is returned: @@ -719,11 +741,13 @@ The population standard deviation of the values in the property `age` is returne ====== .Query +// tag::functions_aggregating_sum[] [source, cypher] ---- MATCH (p:Person) RETURN sum(p.age) ---- +// end::functions_aggregating_sum[] The sum of all the values in the property `age` is returned: @@ -744,11 +768,13 @@ The sum of all the values in the property `age` is returned: ====== .Query +// tag::functions_aggregating_sum_duration[] [source, cypher] ---- UNWIND [duration('P2DT3H'), duration('PT1H45S')] AS dur RETURN sum(dur) ---- +// end::functions_aggregating_sum_duration[] The sum of the two supplied durations is returned: diff --git a/modules/ROOT/pages/functions/database.adoc b/modules/ROOT/pages/functions/database.adoc index 929d72d90..54c183b3c 100644 --- a/modules/ROOT/pages/functions/database.adoc +++ b/modules/ROOT/pages/functions/database.adoc @@ -26,11 +26,13 @@ ====== .Query +// tag::functions_database_name_from_element_id[] [source, cypher, indent=0] ---- WITH "2:efc7577d-022a-107c-a736-dbcdfc189c03:0" AS eid RETURN db.nameFromElementId(eid) AS name ---- +// end::functions_database_name_from_element_id[] Returns the name of the database which the element id belongs to. diff --git a/modules/ROOT/pages/functions/graph.adoc b/modules/ROOT/pages/functions/graph.adoc index 9404b48f5..85f7fd526 100644 --- a/modules/ROOT/pages/functions/graph.adoc +++ b/modules/ROOT/pages/functions/graph.adoc @@ -34,10 +34,12 @@ CREATE ALIAS composite.third FOR DATABASE dbc; ---- .Query +// tag::functions_graph_names[] [source, cypher, indent=0] ---- RETURN graph.names() AS name ---- +// end::functions_graph_names[] The names of all graphs on the current composite database are returned. @@ -91,11 +93,13 @@ CREATE ALIAS composite.third FOR DATABASE dbc ---- .Query +// tag::functions_graph_properties_by_name[] [source, cypher, indent=0] ---- UNWIND graph.names() AS name RETURN name, graph.propertiesByName(name) AS props ---- +// end::functions_graph_properties_by_name[] Properties for all graphs on the current composite database are returned. @@ -150,7 +154,8 @@ For more information, see xref:subqueries/call-subquery.adoc#import-variables[CA ====== .Query -[source, cypher, indent=0] +// tag::functions_graph_by_name[] +[source, cypher, role=noplay] ---- UNWIND graph.names() AS graphName CALL () { @@ -160,6 +165,7 @@ CALL () { } RETURN n ---- +// end::functions_graph_by_name[] Returns all nodes from all graphs on the current composite database. @@ -194,10 +200,12 @@ For more information, see xref:subqueries/call-subquery.adoc#import-variables[CA In this example, it is assumed that the DBMS contains a composite database constituent, which contains the element id `4:c0a65d96-4993-4b0c-b036-e7ebd9174905:0`. .Query +// tag::functions_graph_by_element_id[] [source, cypher, role=test-skip] ---- USE graph.byElementId("4:c0a65d96-4993-4b0c-b036-e7ebd9174905:0") MATCH (n) RETURN n ---- +// end::functions_graph_by_element_id[] ====== diff --git a/modules/ROOT/pages/functions/list.adoc b/modules/ROOT/pages/functions/list.adoc index 1ff0cd547..7dc9e3fd7 100644 --- a/modules/ROOT/pages/functions/list.adoc +++ b/modules/ROOT/pages/functions/list.adoc @@ -56,11 +56,13 @@ CREATE ====== .Query +// tag::functions_list_keys[] [source, cypher] ---- MATCH (a) WHERE a.name = 'Alice' RETURN keys(a) ---- +// end::functions_list_keys[] A `LIST` containing the names of all the properties on the node bound to `a` is returned. @@ -103,11 +105,13 @@ A `LIST` containing the names of all the properties on the node bound to ====== .Query +// tag::functions_list_labels[] [source, cypher] ---- MATCH (a) WHERE a.name = 'Alice' RETURN labels(a) ---- +// end::functions_list_labels[] A `LIST` containing all the labels of the node bound to `a` is returned. @@ -148,12 +152,14 @@ A `LIST` containing all the labels of the node bound to `a` is returned. ====== .Query +// tag::functions_list_nodes[] [source, cypher] ---- MATCH p = (a)-->(b)-->(c) WHERE a.name = 'Alice' AND c.name = 'Eskil' RETURN nodes(p) ---- +// end::functions_list_nodes[] A `LIST` containing all the nodes in the path `p` is returned. @@ -197,10 +203,12 @@ The only exception where the range does not contain `start` are empty ranges. ====== .Query +// tag::functions_list_range[] [source, cypher] ---- RETURN range(0, 10), range(2, 18, 3), range(0, 5, -1) ---- +// end::functions_list_range[] Three lists of numbers in the given ranges are returned. @@ -237,12 +245,14 @@ This function is analogous to the `fold` or `reduce` method in functional langua ====== .Query +// tag::functions_list_reduce[] [source, cypher] ---- MATCH p = (a)-->(b)-->(c) WHERE a.name = 'Alice' AND b.name = 'Bob' AND c.name = 'Daniel' RETURN reduce(totalAge = 0, n IN nodes(p) | totalAge + n.age) AS reduction ---- +// end::functions_list_reduce[] The `age` property of all `NODE` values in the `PATH` are summed and returned as a single value. @@ -283,12 +293,14 @@ The `age` property of all `NODE` values in the `PATH` are summed and returned as ====== .Query +// tag::functions_list_relationships[] [source, cypher] ---- MATCH p = (a)-->(b)-->(c) WHERE a.name = 'Alice' AND c.name = 'Eskil' RETURN relationships(p) ---- +// end::functions_list_relationships[] A `LIST` containing all the `RELATIONSHIP` values in the `PATH` `p` is returned. @@ -330,11 +342,13 @@ A `LIST` containing all the `RELATIONSHIP` values in the `PATH` `p ====== .Query +// tag::functions_list_reverse[] [source, cypher] ---- WITH [4923,'abc',521, null, 487] AS ids RETURN reverse(ids) ---- +// end::functions_list_reverse[] .Result [role="queryresult",options="header,footer",cols="1*` comprising all but the first element of the `likedColors` property are returned. @@ -414,12 +430,14 @@ The property named `likedColors` and a `LIST` comprising all but the first ====== .Query +// tag::functions_list_to_boolean_list[] [source, cypher, indent=0] ---- RETURN toBooleanList(null) as noList, toBooleanList([null, null]) as nullsInList, toBooleanList(['a string', true, 'false', null, ['A','B']]) as mixedList ---- +// end::functions_list_to_boolean_list[] .Result [role="queryresult",options="header,footer",cols="3*(b) @@ -69,6 +70,7 @@ WHERE AND all(x IN nodes(p) WHERE x.age < 60) RETURN p ---- +// end::functions_predicate_all[] All nodes in the returned paths will have a property `age` with a value lower than `60`: @@ -110,12 +112,14 @@ image::predicate_function_example.svg[width="300",role="middle"] ====== .Query +// tag::functions_predicate_any[] [source, cypher, indent=0] ---- MATCH (p:Person) WHERE any(nationality IN p.nationality WHERE nationality = 'American') RETURN p ---- +// end::functions_predicate_any[] The query returns the `Person` nodes with the `nationality` property value `American`: @@ -160,6 +164,7 @@ To check if a property is not `null` use the xref::syntax/operators.adoc#cypher- ====== .Query +// tag::functions_predicate_exists[] [source, cypher, indent=0] ---- MATCH (p:Person) @@ -167,6 +172,7 @@ RETURN p.name AS name, exists((p)-[:ACTED_IN]->()) AS has_acted_in_rel ---- +// end::functions_predicate_exists[] This query returns the `name` property of every `Person` node, along with a boolean (`true` or `false`) indicating if those nodes have an `ACTED_IN` relationship in the graph. @@ -209,12 +215,14 @@ For information about the `EXISTS` subquery, which is more versatile than the `e ====== .Query +// tag::functions_predicate_is_empty[] [source, cypher] ---- MATCH (p:Person) WHERE NOT isEmpty(p.nationality) RETURN p.name, p.nationality ---- +// end::functions_predicate_is_empty[] This query returns every `Person` node in the graph with a set `nationality` property value (i.e., all `Person` nodes except for `Jessica Chastain`): @@ -310,6 +318,7 @@ xref:syntax/operators.adoc#cypher-comparison[`IS NULL` or `IS NOT NULL`] should ====== .Query +// tag::functions_predicate_none[] [source, cypher, indent=0] ---- MATCH p = (n)-[*]->(b) @@ -318,6 +327,7 @@ WHERE AND none(x IN nodes(p) WHERE x.age > 60) RETURN p ---- +// end::functions_predicate_none[] No node in the returned path has an `age` property with a greater value than `60`: @@ -361,6 +371,7 @@ image::predicate_function_example.svg[width="300",role="middle"] ====== .Query +// tag::functions_predicate_single[] [source, cypher, indent=0] ---- MATCH p = (n)-->(b) @@ -369,6 +380,7 @@ WHERE AND single(x IN nodes(p) WHERE x.nationality = 'Northern Irish') RETURN p ---- +// end::functions_predicate_single[] In every returned path there is exactly one node which has the `nationality` property value `Northern Irish`: diff --git a/modules/ROOT/pages/functions/scalar.adoc b/modules/ROOT/pages/functions/scalar.adoc index 8baa1844d..cc17fdc3a 100644 --- a/modules/ROOT/pages/functions/scalar.adoc +++ b/modules/ROOT/pages/functions/scalar.adoc @@ -57,10 +57,12 @@ This function is an alias of the xref::functions/scalar.adoc#functions-size[`siz ====== .Query +// tag::functions_scalar_char_length[] [source, cypher, indent=0] ---- RETURN char_length('Alice') ---- +// end::functions_scalar_char_length[] .Result [role="queryresult",options="header,footer",cols="1*(b)-->(c) WHERE a.name = 'Alice' RETURN length(p) ---- +// end::functions_scalar_length[] The length of the path `p` is returned. @@ -553,10 +571,12 @@ The null value is returned as the two parameters are equivalent. ====== .Query +// tag::functions_scalar_null_if[] [source, cypher, indent=0] ---- RETURN nullIf("abc", "def") ---- +// end::functions_scalar_null_if[] The first parameter, "abc", is returned, as the two parameters are not equivalent. @@ -627,11 +647,13 @@ RETURN a.name AS name, coalesce(nullIf(a.eyes, "Brown"), "Hazel") AS eyeColor ====== .Query +// tag::functions_scalar_properties[] [source, cypher, indent=0] ---- CREATE (p:Person {name: 'Stefan', city: 'Berlin'}) RETURN properties(p) ---- +// end::functions_scalar_properties[] .Result [role="queryresult",options="header,footer",cols="1*() WHERE n.name = 'Alice' RETURN type(r) ---- +// end::functions_scalar_type[] The relationship type of `r` is returned. @@ -1245,11 +1289,13 @@ See the xref::values-and-types/type-predicate.adoc[type predicate expression] fo ====== .Query +// tag::functions_scalar_value_type[] [source, cypher, indent=0] ---- UNWIND ["abc", 1, 2.0, true, [date()]] AS value RETURN valueType(value) AS result ---- +// end::functions_scalar_value_type[] .Result [role="queryresult",options="header,footer",cols="1*(o:Office) @@ -345,6 +350,7 @@ WITH point({longitude: o.longitude, latitude: o.latitude}) AS officePoint RETURN round(point.distance(trainPoint, officePoint)) AS travelDistance ---- +// end::functions_spatial_point_wgs_84_2d[] The distance between the train station in Copenhagen and the Neo4j office in Malmo is returned. @@ -415,6 +421,7 @@ If `null` is provided as one or both of the arguments, `null` is returned. ====== .Query +// tag::functions_spatial_point_wgs_84_3d[] [source, cypher] ---- WITH @@ -422,6 +429,7 @@ WITH point({x: 10, y: 10, crs: 'cartesian'}) AS upperRight RETURN point.withinBBox(point({x: 5, y: 5, crs: 'cartesian'}), lowerLeft, upperRight) AS result ---- +// end::functions_spatial_point_wgs_84_3d[] Checking if a point in _Cartesian_ CRS is contained in the bounding box. @@ -442,6 +450,7 @@ Checking if a point in _Cartesian_ CRS is contained in the bounding box. ====== .Query +// tag::functions_spatial_point_cartesian_2d[] [source, cypher] ---- WITH @@ -451,6 +460,7 @@ MATCH (t:TrainStation) WHERE point.withinBBox(point({longitude: t.longitude, latitude: t.latitude}), lowerLeft, upperRight) RETURN count(t) ---- +// end::functions_spatial_point_cartesian_2d[] Finds all train stations contained in a bounding box around Copenhagen. @@ -498,6 +508,7 @@ A bounding box that crosses the 180th meridian. ====== .Query +// tag::functions_spatial_point_cartesian_3d[] [source, cypher] ---- RETURN @@ -507,6 +518,7 @@ RETURN point({longitude: 57.0, latitude: 13.0}) ) AS in ---- +// end::functions_spatial_point_cartesian_3d[] If `null` is provided as any of the arguments, `null` is returned. diff --git a/modules/ROOT/pages/functions/string.adoc b/modules/ROOT/pages/functions/string.adoc index 68725bd94..fef3a40d7 100644 --- a/modules/ROOT/pages/functions/string.adoc +++ b/modules/ROOT/pages/functions/string.adoc @@ -48,10 +48,12 @@ See also xref::syntax/operators.adoc#query-operators-string[String operators]. ====== .Query +// tag::functions_string_btrim[] [source, cypher, indent=0] ---- RETURN btrim(' hello '), btrim('xxyyhelloxyxy', 'xy') ---- +// end::functions_string_btrim[] .Result [role="queryresult",options="header,footer",cols="2*