如何限制密码的整体联合
How to limit overall union in cypher
我有这些节点:
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)
// post 属于标签
(user) - [: READ{read_date}] -> (thread)
// 用户读取 post
(user) - [: BEING_REPLIED{post_date}] -> (thread)
// 用户在 post 中收到另一个用户对其评论的回复
(user) - [: BEING_MENTIONED{post_date}] -> (thread)
// 该用户在 post 中被另一个用户评论提及
我想获取 10 个用户被其他用户回复或提及的 posts,然后是属于用户关注但用户尚未阅读的标签的 posts显示在每个用户的提要中,我在查询中使用了多个联合但不能限制到总数,结果形式仅限于最后一个联合
我写的密码如下:
MATCH (u:User {user_id:3})-[rp:BEING_REPLIED]->(th:Thread)<-[r:READ]-(u:User {user_id:3})
WHERE rp.post_date> r.read_date
return u.user_id as user_id,th.thread_id as thread_id,
duration.inDays(datetime(),datetime(rp.post_date)).days*10 + 1000000 AS point
UNION ALL
MATCH (u:User {user_id:3})-[m:BEING_MENTIONED]->(th:Thread)<-[r:READ]-(u:User {user_id:3})
WHERE m.post_date> r.read_date
return u.user_id as user_id,th.thread_id as thread_id,
duration.inDays(datetime(),datetime(m.post_date)).days*10 + 1000000 AS point
UNION ALL
MATCH (u:User {user_id:3})-[m:BEING_MENTIONED]->(th:Thread)
WHERE NOT EXISTS ((u)-[:READ]->(th))
return u.user_id as user_id,th.thread_id as thread_id,
duration.inDays(datetime(),datetime(m.post_date)).days*10 + 1000000 AS point
MATCH (u:User)-[:FOLLOWED]->(t:Tag)<-[:BELONG_TO]->(th)
WHERE u.user_id = 3 AND NOT EXISTS((u)-[]->(th))
WITH u.user_id AS user_id, th.thread_id AS thread_id,
(0.5*th.like_count + 0.3*th.comment_count + 0.005*th.view_count
+ duration.inDays(datetime(),datetime(th.published_date)).days*100) AS point
ORDER BY point desc
RETURN DISTINCT user_id, thread_id, point
UNION
MATCH (u:User)-[:FOLLOWED]->(t:Tag)<-[:BELONG_TO]->(th)
WHERE u.user_id = 3 AND NOT EXISTS((u)-[]->(th))
AND NOT th.rating_total IS NULL
WITH u.user_id AS user_id, th.thread_id AS thread_id,
(duration.inDays(datetime(),datetime(th.published_date)).days*150 + 30*th.rating_total) AS point
ORDER BY point desc, th.published_date desc
RETURN DISTINCT user_id, thread_id, point
LIMIT 10
我如何设置这个查询限制?
感谢您的帮助!
你需要子查询,你应该使用 Neo4j 4.0.x 或更高版本,这允许你执行 post-UNION processing
在子查询中使用 UNION ALL,在其外部使用 LIMIT 10,应该可以让您得到想要的结果。
我有这些节点:
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)
// post 属于标签(user) - [: READ{read_date}] -> (thread)
// 用户读取 post(user) - [: BEING_REPLIED{post_date}] -> (thread)
// 用户在 post 中收到另一个用户对其评论的回复
(user) - [: BEING_MENTIONED{post_date}] -> (thread)
// 该用户在 post 中被另一个用户评论提及
我想获取 10 个用户被其他用户回复或提及的 posts,然后是属于用户关注但用户尚未阅读的标签的 posts显示在每个用户的提要中,我在查询中使用了多个联合但不能限制到总数,结果形式仅限于最后一个联合 我写的密码如下:
MATCH (u:User {user_id:3})-[rp:BEING_REPLIED]->(th:Thread)<-[r:READ]-(u:User {user_id:3})
WHERE rp.post_date> r.read_date
return u.user_id as user_id,th.thread_id as thread_id,
duration.inDays(datetime(),datetime(rp.post_date)).days*10 + 1000000 AS point
UNION ALL
MATCH (u:User {user_id:3})-[m:BEING_MENTIONED]->(th:Thread)<-[r:READ]-(u:User {user_id:3})
WHERE m.post_date> r.read_date
return u.user_id as user_id,th.thread_id as thread_id,
duration.inDays(datetime(),datetime(m.post_date)).days*10 + 1000000 AS point
UNION ALL
MATCH (u:User {user_id:3})-[m:BEING_MENTIONED]->(th:Thread)
WHERE NOT EXISTS ((u)-[:READ]->(th))
return u.user_id as user_id,th.thread_id as thread_id,
duration.inDays(datetime(),datetime(m.post_date)).days*10 + 1000000 AS point
MATCH (u:User)-[:FOLLOWED]->(t:Tag)<-[:BELONG_TO]->(th)
WHERE u.user_id = 3 AND NOT EXISTS((u)-[]->(th))
WITH u.user_id AS user_id, th.thread_id AS thread_id,
(0.5*th.like_count + 0.3*th.comment_count + 0.005*th.view_count
+ duration.inDays(datetime(),datetime(th.published_date)).days*100) AS point
ORDER BY point desc
RETURN DISTINCT user_id, thread_id, point
UNION
MATCH (u:User)-[:FOLLOWED]->(t:Tag)<-[:BELONG_TO]->(th)
WHERE u.user_id = 3 AND NOT EXISTS((u)-[]->(th))
AND NOT th.rating_total IS NULL
WITH u.user_id AS user_id, th.thread_id AS thread_id,
(duration.inDays(datetime(),datetime(th.published_date)).days*150 + 30*th.rating_total) AS point
ORDER BY point desc, th.published_date desc
RETURN DISTINCT user_id, thread_id, point
LIMIT 10
我如何设置这个查询限制?
感谢您的帮助!
你需要子查询,你应该使用 Neo4j 4.0.x 或更高版本,这允许你执行 post-UNION processing
在子查询中使用 UNION ALL,在其外部使用 LIMIT 10,应该可以让您得到想要的结果。