Last active
February 26, 2018 03:21
-
-
Save sulram/fdbcd638a5221678bf5fc45ef6403ad1 to your computer and use it in GitHub Desktop.
This file contains 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
CREATE CONSTRAINT ON (e:Empresa) ASSERT e.cnpj IS UNIQUE | |
CREATE CONSTRAINT ON (u:UF) ASSERT u.nome IS UNIQUE | |
CREATE INDEX ON :Socio(nome) | |
USING PERIODIC COMMIT | |
LOAD CSV WITH HEADERS FROM 'file:///Brasil.csv' AS line | |
MERGE (empresa:Empresa { nome: line.nome_empresa, cnpj: line.cnpj_empresa }) | |
MERGE (socio:Socio { nome: line.nome_socio, tipo: line.tipo_socio }) | |
MERGE (uf:UF { nome: line.unidade_federativa }) | |
CREATE (socio)-[:SOCIO_EM {qualificacao: line.qualificacao_socio}]->(empresa) | |
MERGE (empresa)-[:LOCALIZADA]->(uf) |
This file contains 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 (n:Socio) where n.nome IN ["FULANO", "BELTRANO"] | |
WITH collect(n) as nodes | |
UNWIND nodes as n | |
UNWIND nodes as m | |
WITH * WHERE id(n) < id(m) | |
MATCH path = allShortestPaths( (n)-[*..10]-(m) ) | |
WHERE NONE (r IN relationships(path) WHERE type(r)= 'LOCALIZADA') | |
RETURN path | |
MATCH (a:Socio { nome: 'FULANO' }),(b:Socio {nome: 'CICLANO'} ), path = shortestPath((a)-[*..15]-(b)) | |
WHERE NONE (r IN relationships(path) WHERE type(r)= 'LOCALIZADA') | |
RETURN path |
This file contains 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
// :Socio STARTS WITH | |
MATCH path = (SOCIO:Socio)-[r:SOCIO_EM]->(EMPRESA:Empresa)-[]->(:UF) | |
WHERE SOCIO.nome STARTS WITH 'MAR' | |
RETURN path LIMIT 25 | |
// :Empresa CONTAINS | |
MATCH path = (:Socio)-[r:SOCIO_EM]->(EMPRESA:Empresa)-[]->(:UF) | |
WHERE EMPRESA.nome CONTAINS 'TV' | |
RETURN path LIMIT 25 | |
// :Socio & :Empresa | |
MATCH path = (SOCIO:Socio)-[r:SOCIO_EM]->(EMPRESA:Empresa)-[]->(UF:UF) | |
WHERE SOCIO.nome CONTAINS 'MAR' | |
AND EMPRESA.nome STARTS WITH 'TV' | |
AND UF.nome CONTAINS 'RJ' | |
RETURN path LIMIT 25 | |
// REGEX Consultar nomes | |
MATCH path = (EMPRESA:Empresa)-[:LOCALIZADA]->(:UF) | |
WHERE EMPRESA.nome =~ '.*BIONIC.*' | |
RETURN path LIMIT 100 | |
// Simple count | |
MATCH (n:Socio {nome: "FULANO DA SILVA"})-[r:SOCIO_EM]->(:Empresa) | |
RETURN COUNT(r) |
This file contains 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 db.indexes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment