用Neo4j为论坛建模
我需要用Neo4j为论坛建模。我有“论坛”节点,其中包含消息,并且这些消息也可以有回复:论坛-->消息-->回复 我用于检索论坛消息及其回复的密码查询是:用Neo4j为论坛建模,neo4j,Neo4j,我需要用Neo4j为论坛建模。我有“论坛”节点,其中包含消息,并且这些消息也可以有回复:论坛-->消息-->回复 我用于检索论坛消息及其回复的密码查询是: start forum=node({forumId}) match forum-[*1..]->msg where (msg.parent=0 and msg.ts<={ts} or msg.parent<>0) return msg ORDER BY msg.ts DESC limit 10 start for
start forum=node({forumId}) match forum-[*1..]->msg
where (msg.parent=0 and msg.ts<={ts} or msg.parent<>0)
return msg ORDER BY msg.ts DESC limit 10
start forum=node({forumId})匹配论坛-[*1..]>msg
其中(msg.parent=0和msg.ts假设您切换到标签并避免ID(因为它们可以循环使用,因此不是稳定的标识符):
在第二个子查询中使用“where has(forum.name)和forum.name=”以及“OPTIONAL MATCH”,效果非常好只返回带有回复的消息。谢谢。啊,是的,可选匹配的捕获很好,我将更新我的答案!关于有,这意味着一些标有FORUM的节点没有名称属性?不,至少在版本2.0.0中,论坛和消息使用不同的标签,“where FORUM.name=”也使用不具有“name”属性的message类型的节点进行评估。我将对此进行调查。您是否在FORUM
变量的MATCH
子句中指定了FORUM
标签?它起作用:MATCH(FORUM:FORUM)where FORUM.name='f1'返回FORUM
它不:MATCH(FORUM:FORUM)节点[2]上不存在属性“name”
MATCH (forum:FORUM)<--(message:MESSAGE {parent:0})
WHERE forum.name = '%s' // where %s identifies the forum in a *stable* way
WITH message // using a subquery allows to apply LIMIT only to main messages
ORDER BY message.ts DESC
LIMIT 10
OPTIONAL MATCH (message)<-[:REPLIES_TO]-(replies)
RETURN message, replies
WHERE forum.name = '%s' AND message.ts > previous_timestamp