This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH { a: "Moscow", b: "New York", date: "20200125", tmin: 1, tmax: 6 } as params | |
MATCH (a:Airport { city: params.a }) | |
WITH params, AVG(a.location.latitude) as ala, AVG(a.location.longitude) as alo | |
MATCH (b:Airport { city: params.b }) | |
WITH params, ala, alo, AVG(b.location.latitude) as bla, AVG(b.location.longitude) as blo | |
WITH params, distance(point({ latitude: ala, longitude: alo }), point({ latitude: bla, longitude: blo })) / 1000 * 1.05 as max | |
MATCH path = ((a:Airport { city: params.a })-[:FLIES_TO*..3]->(b:Airport { city: params.b })) | |
WHERE apoc.coll.sum([x IN relationships(path) | x.distance ]) <= max AND SIZE(apoc.coll.duplicates([ x IN nodes(path) | x.city ])) = 0 | |
WITH nodes(path) as routes, params | |
WITH { route: routes, size: SIZE(routes) } as list, params |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH { a: "Moscow", b: "New York", date: "20200101" } as params | |
MATCH (a:Airport { city: params.a }) | |
WITH params, AVG(a.location.latitude) as ala, AVG(a.location.longitude) as alo | |
MATCH (b:Airport { city: params.b }) | |
WITH params, ala, alo, AVG(b.location.latitude) as bla, AVG(b.location.longitude) as blo | |
WITH params, distance(point({ latitude: ala, longitude: alo }), point({ latitude: bla, longitude: blo })) / 1000 * 1.05 as max | |
MATCH path = ((a:Airport { city: params.a })-[:FLIES_TO*..3]->(b:Airport { city: params.b })) | |
WHERE apoc.coll.sum([x IN relationships(path) | x.distance ]) <= max AND SIZE(apoc.coll.duplicates([ x IN nodes(path) | x.city ])) = 0 | |
WITH nodes(path) as routes, params | |
WITH { route: routes, size: SIZE(routes) } as list, params |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH { a: "Moscow", b: "New York" } as params | |
MATCH (a:Airport { city: params.a }), (b:Airport { city: params.b }) | |
WITH params, AVG(a.location.latitude) as ala, AVG(a.location.longitude) as alo, AVG(b.location.latitude) as bla, AVG(b.location.longitude) as blo | |
WITH params { .*, max: distance(point({ latitude: ala, longitude: alo }), point({ latitude: bla, longitude: blo })) / 1000 * 1.05 } | |
MATCH path = ((a:Airport { city: params.a })-[:FLIES_TO*..3]->(b:Airport { city: params.b })) | |
WHERE apoc.coll.sum([x IN relationships(path) | x.distance ]) <= params.max AND SIZE(apoc.coll.duplicates([ x IN nodes(path) | x.city ])) = 0 | |
RETURN nodes(path) as routes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH { a: "Moscow", b: "New York" } as params | |
MATCH path = ((a:Airport { city: params.a })-[:FLIES_TO*..3]->(b:Airport { city: params.b })) | |
WITH nodes(path) as routes | |
RETURN routes, SIZE(routes) - 2 as stops | |
ORDER BY stops |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH { date: "20200101" } as params | |
UNWIND [[{code: 'BKK'}, { code: 'KIX'}], [ { code: 'KIX'}, {code: 'LAX'}]] as pair | |
CALL apoc.cypher.run("MATCH (ad:AirportDay { code: \"" + pair[0].code + "_" + params.date + "\" })-[:" + pair[0].code + "_FLIGHT]->(f:Flight)-[:" + pair[0].code + "_FLIGHT]->(bd:AirportDay { code: \"" + pair[1].code + "_" + params.date + "\" }) MATCH (f)-[:OPERATED_BY]->(a:Airline) RETURN f as flight, a as company, ($pair[0].code + $pair[1].code) as key", { pair: pair }) yield value | |
WITH pair, collect(distinct value) as flights | |
RETURN * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// roots | |
MATCH (n) DETACH DELETE n; | |
CREATE | |
(n1:Root:Red { id:'N1', color: "Red", size: 1000 }), | |
(n2:Root:Green { id:'N2', color: "Green", size: 2000 }), | |
(n3:Root:Blue { id:'N3', color: "Blue", size: 3000 }), | |
(n4:Root:Purple { id:'N2', color: "Purple", size: 2000 }), | |
(n5:Root:Orange { id:'N1', color: "Orange", size: 3000 }); | |
MATCH (n1 {id:'N1'}), (n2 {id:'N2'}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ ! -d /data/databases/flights.db ]; then { /var/lib/neo4j/bin/neo4j-admin import | |
--database=flights.db | |
--mode=csv | |
--nodes:Airline="/var/lib/neo4j/import/airlines.csv" | |
--nodes:Airport="/var/lib/neo4j/import/airports.csv" | |
--nodes:Flight="/var/lib/neo4j/import/flights_header.csv,/var/lib/neo4j/import/flights_data_.*" | |
--nodes:AirportDay="/var/lib/neo4j/import/airportDay_header.csv,/var/lib/neo4j/import/airportDay_data_.*" | |
--relationships:FLIES_TO="/var/lib/neo4j/import/fliesTo.csv" | |
--relationships:HAS_DAY="/var/lib/neo4j/import/hasDay_header.csv,/var/lib/neo4j/import/hasDay_data_.*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
Airline(first: 10){ | |
code | |
name | |
flights(first: 5) { | |
flightNumber | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CALL graphql.idl("type Airline { code: String! name: String! country: String! }"); | |
CALL graphql.schema(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (o:Organization)-[:CONTAINS]->(d:Department) | |
RETURN * | |
MATCH (p:Person)-[:WORK_FOR]->(o:Organization) | |
RETURN * | |
MATCH (o:Organization)-[:CONTAINS]->(d:Department)-[:LEAD_BY]->(p:Person) | |
RETURN d, p | |
MATCH (p:Project)-[:OWNED_BY]->(d:Department) |