Q22: Add DISTINCT to limit interim results
// Q22. International dialog
/*
:param {
- country1: 'Japan',
- country2: 'Ethiopia'
+ country1: 'Mexico',
+ country2: 'Indonesia'
}
*/
MATCH
@@ -11,19 +11,19 @@ MATCH
WITH person1, person2, city1, 0 AS score
// subscore 1
OPTIONAL MATCH (person1)<-[:HAS_CREATOR]-(c:Comment)-[:REPLY_OF]->(:Message)-[:HAS_CREATOR]->(person2)
-WITH person1, person2, city1, score + (CASE c WHEN null THEN 0 ELSE 4 END) AS score
+WITH DISTINCT person1, person2, city1, score + (CASE c WHEN null THEN 0 ELSE 4 END) AS score
// subscore 2
OPTIONAL MATCH (person1)<-[:HAS_CREATOR]-(m:Message)<-[:REPLY_OF]-(:Comment)-[:HAS_CREATOR]->(person2)
-WITH person1, person2, city1, score + (CASE m WHEN null THEN 0 ELSE 1 END) AS score
+WITH DISTINCT person1, person2, city1, score + (CASE m WHEN null THEN 0 ELSE 1 END) AS score
// subscore 3
OPTIONAL MATCH (person1)-[k:KNOWS]-(person2)
-WITH person1, person2, city1, score + (CASE k WHEN null THEN 0 ELSE 15 END) AS score
+WITH DISTINCT person1, person2, city1, score + (CASE k WHEN null THEN 0 ELSE 15 END) AS score
// subscore 4
OPTIONAL MATCH (person1)-[:LIKES]->(m:Message)-[:HAS_CREATOR]->(person2)
-WITH person1, person2, city1, score + (CASE m WHEN null THEN 0 ELSE 10 END) AS score
+WITH DISTINCT person1, person2, city1, score + (CASE m WHEN null THEN 0 ELSE 10 END) AS score
// subscore 5
OPTIONAL MATCH (person1)<-[:HAS_CREATOR]-(m:Message)<-[:LIKES]-(person2)
-WITH person1, person2, city1, score + (CASE m WHEN null THEN 0 ELSE 1 END) AS score
+WITH DISTINCT person1, person2, city1, score + (CASE m WHEN null THEN 0 ELSE 1 END) AS score
// preorder
ORDER BY
city1.name ASC,
