This repository has been archived by the owner on Apr 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
bi-10.cypher
68 lines (68 loc) · 1.69 KB
/
bi-10.cypher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Q10. Central Person for a Tag
/*
:param {
tag: 'John_Rhys-Davies',
date: 20120122000000000
}
*/
MATCH (tag:Tag {name: $tag})
// score
OPTIONAL MATCH (tag)<-[interest:HAS_INTEREST]-(person:Person)
WITH tag, collect(person) AS interestedPersons
OPTIONAL MATCH (tag)<-[:HAS_TAG]-(message:Message)-[:HAS_CREATOR]->(person:Person)
WHERE message.creationDate > $date
WITH tag, interestedPersons, collect(person) AS persons
WITH tag, interestedPersons + persons AS persons
UNWIND persons AS person
// poor man's disjunct union (should be changed to UNION + post-union processing in the future)
WITH DISTINCT tag, person
OPTIONAL MATCH (tag)<-[interest:HAS_INTEREST]-(person:Person)
WITH
tag,
person,
count(interest) AS score // multiple by 100 deferred to next query part
OPTIONAL MATCH (tag)<-[:HAS_TAG]-(message:Message)-[:HAS_CREATOR]->(person)
WHERE message.creationDate > $date
WITH
tag,
person,
100 * score AS score,
count(message) AS messageCount
WITH
tag,
person,
score + messageCount AS score
MATCH (person)-[:KNOWS]-(friend)
WITH
tag,
person,
score,
friend
OPTIONAL MATCH (tag)<-[interest:HAS_INTEREST]-(friend:Person)
WITH
tag,
person,
score,
friend,
count(interest) AS friendScore // multiple by 100 deferred to next query part
OPTIONAL MATCH (tag)<-[:HAS_TAG]-(message:Message)-[:HAS_CREATOR]->(friend)
WHERE message.creationDate > $date
WITH
person,
score,
friend,
100 * friendScore AS friendScore,
count(message) AS messageCount
WITH
person,
score,
friend,
friendScore + messageCount AS friendScore
RETURN
person.id,
score,
sum(friendScore) AS friendsScore
ORDER BY
score + friendsScore DESC,
person.id ASC
LIMIT 100