我有这些节点:
user{user_id}: users
thread{thread_id, post_date} : posts
tag_id{tag_id}: the tag of the post
这些关系:
(user) - [: FOLLOWED] -> (tag)
//用户关注标签(thread) - [: BELONG_TO] -> (tag)
//帖子属于标签(user) - [: READ] -> (thread)
//用户阅读帖子现在,我要查询用户未读的5个帖子之后的每个标签。我写的密码如下:
MATCH (u:User)-[:FOLLOWED]->(t:Tag)
WHERE u.id = 39792
WITH collect(t) as tLists
UNWIND tLists as t
MERGE (u:User)-[:FOLLOWED]->(t:Tag)<-[:BELONG_TO]-(th:Thread)<-[r:READ]-()
WHERE not (u)-[:READ]->(th)
RETURN u.id, th.id, t.id, duration.inDays(datetime(), datetime({ epochmillis: apoc.date.parse(th.post_date)})).days as time, count(r) as count_view
ORDER BY time DESC, count_view DESC
LIMIT 5
但是它不起作用。帮帮我
答案 0 :(得分:0)
MERGE
以避免不必要的结果。)COUNT
),除非您已阅读文档并了解如何使用它们。特别是,您必须了解什么是“分组键”以及它们如何影响聚合函数的行为。此查询可能对您有用:
MATCH (u:User)-[:FOLLOWED]->(t:Tag)<-[:BELONG_TO]->(th)
WHERE u.id = 39792 AND NOT EXISTS((u)-[:READ]->(th))
RETURN u.id, th.id, t.id,
duration.inDays(datetime(), datetime({ epochmillis: apoc.date.parse(th.post_date)})).days AS days,
SIZE((th)<-[:READ]-()) as count_view
ORDER BY days DESC, count_view DESC
LIMIT 5
[更新]
这是一种获取5个最新线程的方式,每个线程紧随其后的是用户尚未阅读的最多视图:
MATCH (u:User)-[:FOLLOWED]->(t:Tag)<-[:BELONG_TO]->(th)
WHERE u.id = 39792 AND NOT EXISTS((u)-[:READ]->(th))
WITH t.id AS tagId, th.id AS threadId
ORDER BY apoc.date.parse(th.post_date) DESC, SIZE((th)<-[:READ]-()) DESC
RETURN tagId, COLLECT(threadId)[..5] AS threads