提交 78299bc4 编写于 作者: M Mark Needham

apoc.log, apoc.spatial, apoc.ttl

上级 96d24ec7
......@@ -25,3 +25,7 @@ apoc.log.debug(message :: STRING?, params = [] :: LIST? OF ANY?) :: VOID
|params|LIST? OF ANY?|[]
|===
[[usage-apoc.log.debug]]
== Usage Examples
include::partial$usage/apoc.log.debug.adoc[]
......@@ -25,3 +25,7 @@ apoc.log.error(message :: STRING?, params = [] :: LIST? OF ANY?) :: VOID
|params|LIST? OF ANY?|[]
|===
[[usage-apoc.log.error]]
== Usage Examples
include::partial$usage/apoc.log.error.adoc[]
......@@ -25,3 +25,7 @@ apoc.log.info(message :: STRING?, params = [] :: LIST? OF ANY?) :: VOID
|params|LIST? OF ANY?|[]
|===
[[usage-apoc.log.info]]
== Usage Examples
include::partial$usage/apoc.log.info.adoc[]
......@@ -25,3 +25,7 @@ apoc.log.warn(message :: STRING?, params = [] :: LIST? OF ANY?) :: VOID
|params|LIST? OF ANY?|[]
|===
[[usage-apoc.log.warn]]
== Usage Examples
include::partial$usage/apoc.log.warn.adoc[]
......@@ -37,5 +37,9 @@ apoc.spatial.geocode(location :: STRING?, maxResults = 100 :: INTEGER?, quotaExc
|description|STRING?
|===
[[usage-apoc.spatial.geocode]]
== Usage Examples
include::partial$usage/apoc.spatial.geocode.adoc[]
xref::misc/spatial.adoc[More documentation of apoc.spatial.geocode,role=more information]
......@@ -35,5 +35,9 @@ apoc.spatial.geocodeOnce(location :: STRING?) :: (location :: MAP?, data :: MAP?
|description|STRING?
|===
[[usage-apoc.spatial.geocodeOnce]]
== Usage Examples
include::partial$usage/apoc.spatial.geocodeOnce.adoc[]
xref::misc/spatial.adoc[More documentation of apoc.spatial.geocodeOnce,role=more information]
......@@ -37,5 +37,9 @@ apoc.spatial.reverseGeocode(latitude :: FLOAT?, longitude :: FLOAT?, quotaExcept
|description|STRING?
|===
[[usage-apoc.spatial.reverseGeocode]]
== Usage Examples
include::partial$usage/apoc.spatial.reverseGeocode.adoc[]
xref::misc/spatial.adoc[More documentation of apoc.spatial.reverseGeocode,role=more information]
......@@ -32,5 +32,9 @@ apoc.spatial.sortByDistance(paths :: LIST? OF PATH?) :: (path :: PATH?, distance
|distance|FLOAT?
|===
[[usage-apoc.spatial.sortByDistance]]
== Usage Examples
include::partial$usage/apoc.spatial.sortByDistance.adoc[]
xref::misc/spatial.adoc[More documentation of apoc.spatial.sortByDistance,role=more information]
......@@ -26,5 +26,12 @@ apoc.ttl.expire(node :: NODE?, time :: INTEGER?, timeUnit :: STRING?) :: VOID
|timeUnit|STRING?|null
|===
== Enable TTL
include::partial$ttl.adoc[]
[[usage-apoc.ttl.expire]]
== Usage Examples
include::partial$usage/apoc.ttl.expire.adoc[]
xref::graph-updates/ttl.adoc[More documentation of apoc.ttl.expire,role=more information]
......@@ -26,5 +26,12 @@ apoc.ttl.expireIn(node :: NODE?, timeDelta :: INTEGER?, timeUnit :: STRING?) ::
|timeUnit|STRING?|null
|===
== Enable TTL
include::partial$ttl.adoc[]
[[usage-apoc.ttl.expireIn]]
== Usage Examples
include::partial$usage/apoc.ttl.expireIn.adoc[]
xref::graph-updates/ttl.adoc[More documentation of apoc.ttl.expireIn,role=more information]
By default TTL is disabled.
We can enable it by setting the following property in `apoc.conf`:
.apoc.conf
[source,properties]
----
apoc.ttl.enabled=true
----
\ No newline at end of file
For this procedure to log messages, we need to set the following config in the Neo4j configuration file:
.$NEO4J_HOME/neo4j.conf
[source,properties]
----
dbms.logs.debug.level=DEBUG
----
We can log a message to `neo4j.log` using the following query:
[source,cypher]
----
CALL apoc.log.debug('Hello %s', ['World']);
----
.neo4j.log
[source,text]
----
CALL apoc.log.debug('Hello %s', ['World']);
----
We can query the contents of `neo4j.log` using xref::overview/apoc.log/apoc.log.stream.adoc[]
\ No newline at end of file
We can log a message to `neo4j.log` using the following query:
[source,cypher]
----
CALL apoc.log.error('Hello %s', ['World']);
----
.neo4j.log
[source,text]
----
2020-11-18 10:22:28.923+0000 ERROR hello_world
----
We can query the contents of `neo4j.log` using xref::overview/apoc.log/apoc.log.stream.adoc[]
\ No newline at end of file
We can log a message to `neo4j.log` using the following query:
[source,cypher]
----
CALL apoc.log.info('Hello %s', ['World']);
----
.neo4j.log
[source,text]
----
2020-11-18 10:18:08.673+0000 INFO hello_world
----
We can query the contents of `neo4j.log` using xref::overview/apoc.log/apoc.log.stream.adoc[]
\ No newline at end of file
We can log a message to `neo4j.log` using the following query:
[source,cypher]
----
CALL apoc.log.warn('Hello %s', ['World']);
----
.neo4j.log
[source,text]
----
2020-11-18 10:21:37.365+0000 WARN hello_world
----
We can query the contents of `neo4j.log` using xref::overview/apoc.log/apoc.log.stream.adoc[]
\ No newline at end of file
[source,cypher]
----
CALL apoc.spatial.geocode('Union House, London');
----
.Results
[opts="header"]
|===
| location | data | latitude | longitude | description
| {description: "Union House, 182-194, Union Street, Bankside, Southwark, London Borough of Southwark, London, Greater London, England, SE1 0LR, Unite
d Kingdom", latitude: 51.503819199999995, longitude: -0.10101882640252435} | {osm_type: "way", osm_id: 77765231, licence: "Data © OpenStreetMap contri
butors, ODbL 1.0. https://osm.org/copyright", boundingbox: ["51.5037439", "51.5038945", "-0.1013092", "-0.1007285"], importance: 0.31100000000000005,
lon: "-0.10101882640252435", display_name: "Union House, 182-194, Union Street, Bankside, Southwark, London Borough of Southwark, London, Greater Lond
on, England, SE1 0LR, United Kingdom", type: "yes", class: "building", place_id: 104116750, lat: "51.503819199999995"} | 51.503819199999995 | -0.10101
882640252435 | "Union House, 182-194, Union Street, Bankside, Southwark, London Borough of Southwark, London, Greater London, England, SE1 0LR, United
Kingdom"
| {description: "Union House, Shepherds Bush Green, Brook Green, London Borough of Hammersmith and Fulham, London, Greater London, England, W12 7DP, U
nited Kingdom", latitude: 51.504723, longitude: -0.2249915937565324} | {osm_type: "way", osm_id: 159245997, licence: "Data © OpenStreetMap contr
ibutors, ODbL 1.0. https://osm.org/copyright", boundingbox: ["51.5045808", "51.5048507", "-0.2251614", "-0.2248218"], importance: 0.31100000000000005,
lon: "-0.2249915937565324", display_name: "Union House, Shepherds Bush Green, Brook Green, London Borough of Hammersmith and Fulham, London, Greater
London, England, W12 7DP, United Kingdom", type: "yes", class: "building", place_id: 123432321, lat: "51.504723"} | 51.504723 | -0.22499
15937565324 | "Union House, Shepherds Bush Green, Brook Green, London Borough of Hammersmith and Fulham, London, Greater London, England, W12 7DP, Un
ited Kingdom"
| {description: "Union House, 6, Martin Lane, Bishopsgate, City of London, Greater London, England, EC4R 0DP, United Kingdom", latitude: 51.510519, lo
ngitude: -0.08806049069724674} | {osm_type: "way", osm_id: 809354346, licence: "Data © OpenStreetMap contr
ibutors, ODbL 1.0. https://osm.org/copyright", boundingbox: ["51.5104519", "51.5106113", "-0.0882068", "-0.0878968"], importance: 0.30100000000000005,
lon: "-0.08806049069724674", display_name: "Union House, 6, Martin Lane, Bishopsgate, City of London, Greater London, England, EC4R 0DP, United Kingd
om", type: "commercial", class: "building", place_id: 289689410, lat: "51.510519"} | 51.510519 | -0.08806
049069724674 | "Union House, 6, Martin Lane, Bishopsgate, City of London, Greater London, England, EC4R 0DP, United Kingdom"
|===
\ No newline at end of file
[source,cypher]
----
CALL apoc.spatial.geocodeOnce('21 rue Paul Bellamy 44000 NANTES FRANCE')
----
.Results
[opts="header"]
|===
| location | data | latitude | longitude | description
| {description: "21, Rue Paul Bellamy, Talensac - Pont Morand, Hauts-Pavés - Saint-Félix, Nantes, Loire-Atlantique, Pays de la Loire, France métropolitaine, 44000, France", latitude: 47.2221667, longitude: -1.5566625} | {osm_type: "node", osm_id: 1730317979, licence: "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright", boundingbox: ["47.2221167", "47.2222167", "-1.5567125", "-1.5566125"], importance: 0.721, lon: "-1.5566625", display_name: "21, Rue Paul Bellamy, Talensac - Pont Morand, Hauts-Pavés - Saint-Félix, Nantes, Loire-Atlantique, Pays de la Loire, France métropolitaine, 44000, France", type: "house", class: "place", place_id: 17843897, lat: "47.2221667"} | 47.2221667 | -1.5566625 | "21, Rue Paul Bellamy, Talensac - Pont Morand, Hauts-Pavés - Saint-Félix, Nantes, Loire-Atlantique, Pays de la Loire, France métropolitaine, 44000, France"
|===
\ No newline at end of file
[source,cypher]
----
CALL apoc.spatial.reverseGeocode(51.5074, 0.1277);
----
.Results
[opts="header"]
|===
| location | data | latitude | longitude | description
| {description: "Crossway, London Borough of Bexley, London, Greater London, England, SE28 8NH, United Kingdom", latitude: 51.50743369498096, longitud
e: 0.1274535888695359} | {country: "United Kingdom", country_code: "gb", road: "Crossway", city: "London", state_district: "Greater London", postcode:
"SE28 8NH", state: "England", city_district: "London Borough of Bexley"} | 51.50743369498096 | 0.1274535888695359 | "Crossway, London Borough of Bexl
ey, London, Greater London, England, SE28 8NH, United Kingdom"
|===
\ No newline at end of file
The examples in this section are based on the following sample graph:
[source, cypher]
----
CREATE (bruges:City {name:"bruges", latitude: 51.2605829, longitude: 3.0817189})
CREATE (brussels:City {name:"brussels", latitude: 50.854954, longitude: 4.3051786})
CREATE (paris:City {name:"paris", latitude: 48.8588376, longitude: 2.2773455})
CREATE (dresden:City {name:"dresden", latitude: 51.0767496, longitude: 13.6321595})
MERGE (bruges)-[:NEXT]->(brussels)
MERGE (brussels)-[:NEXT]->(dresden)
MERGE (brussels)-[:NEXT]->(paris)
MERGE (bruges)-[:NEXT]->(paris)
MERGE (paris)-[:NEXT]->(dresden);
----
[source, cypher]
----
MATCH (a:City {name:'bruges'}), (b:City {name:'dresden'})
MATCH p=(a)-[*]->(b)
WITH collect(p) as paths
CALL apoc.spatial.sortByDistance(paths)
YIELD path, distance
RETURN path, distance;
----
.Results
[opts="header"]
|===
| path | distance
| (:City {name: "bruges", latitude: 51.2605829, longitude: 3.0817189})-[:NEXT]->(:City {name: "brussels", latitude: 50.854954, longitude: 4.3051786})-
[:NEXT]->(:City {name: "dresden", latitude: 51.0767496, longitude: 13.6321595})
| 749.8210570020021
| (:City {name: "bruges", latitude: 51.2605829, longitude: 3.0817189})-[:NEXT]->(:City {name: "paris", latitude: 48.8588376, longitude: 2.2773455})-[:
NEXT]->(:City {name: "dresden", latitude: 51.0767496, longitude: 13.6321595})
| 1120.8512195180913
| (:City {name: "bruges", latitude: 51.2605829, longitude: 3.0817189})-[:NEXT]->(:City {name: "brussels", latitude: 50.854954, longitude: 4.3051786})-
[:NEXT]->(:City {name: "paris", latitude: 48.8588376, longitude: 2.2773455})-[:NEXT]->(:City {name: "dresden", latitude: 51.0767496, longitude: 13.632
1595}) | 1209.661314133324
|===
The examples in this section are based on the following sample graph:
include::partial$createExportGraph.adoc[]
We can expire any people that have produced a movie by running the following query:
[source,cypher]
----
WITH apoc.date.add(datetime().epochSeconds, "s", 5, "s") AS fiveSecondsTime
MATCH (movie:Movie)<-[produced:PRODUCED]-(person:Person)
CALL apoc.ttl.expire(person,fiveSecondsTime,'s')
RETURN movie, produced, person;
----
.Results
[opts="header"]
|===
| movie | produced | person
| (:Movie {tagline: "Welcome to the Real World", title: "The Matrix", released: 1999}) | [:PRODUCED] | (:Person:TTL {name: "Joel Silver", ttl: 1605698172000, born: 1952})
|===
This node (and its relationships) will expire at `1605698172000` (5 seconds from now at the time of writing):
[source,cypher]
----
RETURN datetime({epochMillis: 1605698172000}) AS expiryTime;
----
.Results
[opts="header"]
|===
| expiryTime
| 2020-11-18T11:16:12Z
|===
The next time that the expiration job runs, we'll see the following output in `neo4j.log`:
.neo4j.log
[source,text]
----
2020-11-18 11:16:40.348+0000 INFO [apoc] TTL: Expired 1 nodes 1 relationships
----
And if we try to look for our producer:
[source,cypher]
----
MATCH (movie:Movie)<-[produced:PRODUCED]-(person:Person)
RETURN movie, produced, person;
----
We won't get any results:
.Results
[opts="header"]
|===
| movie | produced | person
|===
\ No newline at end of file
The examples in this section are based on the following sample graph:
include::partial$createExportGraph.adoc[]
We can expire any people that have produced a movie by running the following query:
[source,cypher]
----
MATCH (movie:Movie)<-[produced:PRODUCED]-(person:Person)
CALL apoc.ttl.expireIn(person, 10,'s')
RETURN movie, produced, person;
----
.Results
[opts="header"]
|===
| movie | produced | person
| (:Movie {tagline: "Welcome to the Real World", title: "The Matrix", released: 1999}) | [:PRODUCED] | (:Person:TTL {name: "Joel Silver", ttl: 1605698768575, born: 1952}
|===
This node (and its relationships) will expire at `1605698768575` (10 seconds from now at the time of writing):
[source,cypher]
----
RETURN datetime({epochMillis: 1605698768575}) AS expiryTime;
----
.Results
[opts="header"]
|===
| expiryTime
| 2020-11-18T11:26:08.575Z
|===
The next time that the expiration job runs, we'll see the following output in `neo4j.log`:
.neo4j.log
[source,text]
----
2020-11-18 11:26:40.357+0000 INFO [apoc] TTL: Expired 1 nodes 1 relationships
----
And if we try to look for our producer:
[source,cypher]
----
MATCH (movie:Movie)<-[produced:PRODUCED]-(person:Person)
RETURN movie, produced, person;
----
We won't get any results:
.Results
[opts="header"]
|===
| movie | produced | person
|===
\ No newline at end of file
......@@ -266,6 +266,7 @@ class DocumentationGenerator {
writeExportToFile(writer, procedure.name().toString());
writeExportToStream(writer, procedure.name().toString());
writeUuid(writer, procedure.name().toString());
writeTTL(writer, procedure.name().toString());
writeNlpDependencies(writer, procedure.name().toString());
writeUsageExample(writer, procedure.name().toString());
writeExtraDocumentation(writer, procedure.name());
......@@ -317,6 +318,13 @@ class DocumentationGenerator {
}
}
private void writeTTL(Writer writer, String name) throws IOException {
if(name.startsWith("apoc.ttl")) {
writer.write("== Enable TTL\n");
writer.write("include::partial$ttl.adoc[]\n\n");
}
}
private void writeNlpDependencies(Writer writer, String name) throws IOException {
if(name.startsWith("apoc.nlp")) {
writer.write("== Install Dependencies\n");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册