/
complexqueries.cfg
97 lines (89 loc) · 4.05 KB
/
complexqueries.cfg
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#
# All the users who the given user answered questions for
#
[user.answered]
query: start user=node:Users(userId="{val}")
match user -[:posted]-> (post) -[:question]-> (question) -[:posted_by]-> (asker)
return user.userId as answererId, post.postId as answerId, asker.userId as questionerId, question.postId as questionId
#
# All the users who have answered a question posted by the given user
# - The second is the same result but using the question's relation to the answer
#
[questions.answered]
query: start user=node:Users(userId="{val}")
match user -[:posted]-> (post) -[:answer]-> (answer) -[:posted_by]-> (answerer)
return user.userId as questionerId, post.postId as questionId, answerer.userId as answererId, answer.postId as answerId
#query: start user=node:Users(userId="{val}")
# match user -[:posted]-> (post) <-[:question]- (answer) -[:posted_by]-> (answerer)
# return user.userId as questionerId, post.postId as questionId, answerer.userId as answererId, answer.postId as answerId
#
# All the tags for the given user's questions
#
[user.question.tags]
query: start user=node:Users(userId="{val}")
match user -[:posted]-> (post) -[:tagged]-> (tag)
return user.userId as questionerId, post.postId as questionId, tag.tagName as tagName
#
# How popular are the tags for a user's questsions?
#
[user.qtags.count]
query: start user=node:Users(userId="{val}")
match user -[:posted]-> (post) -[:tagged]-> (tag) <-[:tagged]- (postsTagged)
return tag.tagName as tagName, count(postsTagged) as tagCount
order by tagCount desc
limit 20
#
# How popular are the tags for the questions a user has answered?
#
[user.atags.count]
query: start user=node:Users(userId="{val}")
match user <-[:posted_by]- (answer) -[:question]-> (question) -[:tagged]-> (tag) <-[:tagged]- (postsTagged)
return tag.tagName as tagName, count(postsTagged) as tagCount
order by tagCount desc
limit 20
#
# How many questions away is a user from the given user
#
[user.qto.user]
query: start startUser=node:Users(userId="{val[0]}"), endUser=node:Users(userId="{val[1]}")
match sp=shortestPath(startUser-[*..10]->endUser)
return sp
#
# Return questions that are tagged like the given one. Returns the matched tags
# as a list for the given question.
#
[similarly.tagged]
query: start startQuestion=node:Posts(postId="{val}")
match startQuestion -[:tagged]-> (tag) <-[:tagged]- (endQuestion)
return endQuestion.postId as questionId, collect(tag.tagName) as tags
order by questionId
exec:result = map(lambda r: [r[0], r[1].replace('[', '').replace(']', '').replace(', ', ',').split(',')], result[0])
result.sort(lambda x,y: cmp(len(x[1]), len(y[1])))
result.reverse()
del result[20:]
result = map(lambda r: {'questionId':r[0], 'tags':r[1]}, result)
result = json.dumps(result)
#
# Return answers of other questions that are tagged with the same tags,
# are in the same accepted state
#
[similar.answers]
query: start startAnswer=node:Posts(postId="{val}")
match startAnswer <-[ra:answer]- (startQuestion) -[:tagged]-> (tag) <-[:tagged]- (otherQuestion) -[rb:answer]-> (endAnswer)
where ra.accepted = rb.accepted
return endAnswer.postId as answerId
limit 20
#
# Find content related to the given set of bookmarks. Sort the results by weight.
#
[weighted.bookmark.recomendations]
query: start bookmark=node:Bookmarks(bookmarkId="{val}")
match bookmark -[br]-> (item) -[inl]- (shared) <-[inr]- (related)
where not(type(inl) =~ /bookmarked_.*/) and
not(type(inr) =~ /bookmarked_.*/) and
(not(related.ntype = 'user') or not(related.name = 'Community'))
return br.weight as weight, related.postId? as postId, related.userId? as userId, related.tagName? as tagName, related.ntype as ntype
order by br.weight desc
limit 40
exec:result = map(lambda r: {'weight':r[0], 'postId':r[1], 'userId':r[2], 'tagName':r[3], 'isAnswer':'true' if r[4] == 'a' else 'false'}, result[0])
result = json.dumps(result)