Modelling a forum with Neo4j -


i need model forum neo4j. have "forums" nodes have messages and, optionally, these messages have replies: forum-->message-->reply

the cypher query using retrieve messages of forum , replies is:

start forum=node({forumid}) match forum-[*1..]->msg  (msg.parent=0 , msg.ts<={ts} or msg.parent<>0)  return msg order msg.ts desc limit 10 

this query retrieves messages time<=ts , replies (a message has parent=0 , reply has parent<>0)

my problem need retrieve pages of 10 messages (limit 10) independently of number or replies.

for example, if had 20 messages , first 1 100 replies, return 10 rows: first message , 9 replies need first 10 messages , 100 replies of first one.

how can limit result based on number of messages , not replies?

the ts property indexed, query efficient when mixing other clauses?

do know better way model kind of forum neo?

supposing switch labels , avoid ids (as can recycled , therefore not stable identifiers):

match (forum:forum)<--(message:message {parent:0}) forum.name = '%s' // %s identifies forum in *stable* way message // using subquery allows apply limit main messages order message.ts desc limit 10  optional match (message)<-[:replies_to]-(replies) return message, replies 

the important change here split reply , message matching in 2 sub-queries, limit clause applies first subquery only.

however, need link relevant replies matched main messages in second subquery (i introduced fictional relationship replies_to link replies messages).

and when need fetch page 2,3,4 etc. need parameter (which biggest message timestamp of previous page, let's previous_timestamp).

the first sub-query clause becomes:

where forum.name = '%s' , message.ts > previous_timestamp 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -