Last active
August 29, 2015 14:05
-
-
Save verdverm/7a6d665dce3daba20c51 to your computer and use it in GitHub Desktop.
neo4j duplicate, symmetric results
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
func findLovers() { | |
stmt := ` | |
MATCH | |
(u1:User)-[:LOVES]->(u2:User)-[:LOVES]->(u1) | |
WHERE u1.name <= u2.name // <- THIS WAS MISSING | |
RETURN u1.name, u2.name | |
ORDER BY u1.name, u2.name | |
` | |
res := []struct { | |
LoverA string `json:"u1.name"` | |
LoverB string `json:"u2.name"` | |
}{} | |
// construct query | |
cq := neoism.CypherQuery{ | |
Statement: stmt, | |
Parameters: nil, | |
Result: &res, | |
} | |
// execute query | |
err := db.Cypher(&cq) | |
panicErr(err) | |
fmt.Println("Lovers:") | |
if len(res) > 0 { | |
for _, n := range res { | |
fmt.Printf(" %s \u2661 %s\n", n.LoverA, n.LoverB) | |
} | |
} else { | |
fmt.Println("No results found") | |
} | |
} | |
// Results: | |
Lovers: | |
Joe ♡ Maria | |
Maria ♡ Joe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment