让我们假设这个模型:
(notification)-[:CONCERNS]->(user)
为了简单起见,让我们想象每个notification
与特定主题相关的聊天条目相关。
因此,当用户进入Football
主题并输入:"嗨大家好!"时,最终创建的notification
包含这些属性(包括其他属性):
topidId
(String)occurredOn
(时间戳(长))body
(字符串 - 聊天消息的摘录)请注意,notification
和topic
之间没有直接关系
事实上,在未来,我不想用用户的通知机制污染Neo4j。
Redis或RDBMS可以更好地处理它。
基本上,如果我运行此查询:
MATCH (user:User {_id: "30c62b1f-4556-4966-b60c-3547d4c8d522"})
WITH user
MATCH user<-[:CONCERNS]-(n:Notification)
RETURN n.topicId AS TopicId, n.body as Body
ORDER BY n.occurredOn DESC
它可以返回:
TopicID Body
123 Fine and you ! // I want to retain only this for Football (123 being Football)
123 Hey! How are you?
456 Yes, I'm here ! // I want to retain only this for tennis (456 being Tennis)
456 Are you here?
如何更改查询以获取此结果,作为每个主题的最新消息。
123 Fine and you !
456 Yes, I'm here !
答案 0 :(得分:0)
这个怎么样?
MATCH (user:User {_id: "30c62b1f-4556-4966-b60c-3547d4c8d522"})
MATCH user<-[:CONCERNS]-(n:Notification)
WITH user, collect(n) AS notifications
ORDER BY n.occurredOn DESC
WITH user, notifications[0] AS notification
RETURN notification.topicId AS TopicId, notification.body as Body
ORDER BY notification.occurredOn DESC