目前正在NEO4J工作,而我在图db中工作。现在我需要对图表db中的记录进行分页。我创建了以下查询
MATCH (n:Question)<-[r1:HAS_QUESTION]-(c:Chapter)
MATCH (c)-[r2:HAS_CHILD]->(t:Topic)-[r3:HAS_QUESTION]->(qstn:Question)
WHERE ID(c)=330
WITH n,qstn WHERE NOT(n:Removed) AND NOT(qstn:Removed)
WITH n,qstn
RETURN n as Question,qstn
在这个查询中我有13个问题节点。但是当我向该查询添加skip和limit时,我只得到7个节点而不是10个。查询是
MATCH (n:Question)<-[r1:HAS_QUESTION]-(c:Chapter)
MATCH (c)-[r2:HAS_CHILD]->(t:Topic)-[r3:HAS_QUESTION]->(qstn:Question)
WHERE id(c)=330 WITH n,qstn
WHERE NOT(n:Removed) AND NOT(qstn:Removed)
WITH n,qstn
RETURN n as Question,qstn
SKIP 0 LIMIT 10;
有人请解释这个查询发生了什么。有没有想法获得10个节点。
示例图的查询如下。
CREATE (c:Chapter {chapter_name:"Biodiversity and Conservation"})
CREATE (t:Topic {topic_name:"Biodiversity Conservation"})
CREATE (q:Question {content: "first question"})
CREATE (t1:Topic {topic_name:"Biodiversity"})
CREATE (q1:Question {content: "second question"})
CREATE (q0:Question {content: "third question"})
CREATE (q01:Question {content: "fourth question"})
CREATE (q2:Question {content: "fifth question"})
CREATE (q3:Question {content: "sixth question"})
CREATE (q4:Question {content: "seventh question"})
CREATE (q5:Question {content: "eighth question"})
CREATE (q6:Question {content: "nineth question"})
CREATE (q7:Question {content: "tenth question"})
CREATE (q8:Question {content: "eleventh question"})
CREATE (q9:Question {content: "twelfth question"})
CREATE (q10:Question {content: "thirteenth question"})
CREATE (q11:Question {content: "fourteenth question"})
CREATE (q12:Question {content: "fifteenth question"})
CREATE (q13:Question {content: "sixteenth question"})
CREATE (c)-[r:HAS_TOPIC]->(t)
CREATE (c)-[r1:HAS_TOPIC]->(t1)
CREATE (t)-[r2:HAS_QUESTION]->(q)
CREATE (t1)-[r3:HAS_QUESTION]->(q1)
CREATE (c)-[r4:HAS_QUESTION]->(q0)
CREATE (c)-[r5:HAS_QUESTION]->(q01)
CREATE (c)-[r6:HAS_QUESTION]->(q2)
CREATE (c)-[r7:HAS_QUESTION]->(q3)
CREATE (c)-[r8:HAS_QUESTION]->(q4)
CREATE (c)-[r9:HAS_QUESTION]->(q5)
CREATE (c)-[r0:HAS_QUESTION]->(q6)
CREATE (c)-[r11:HAS_QUESTION]->(q7)
CREATE (c)-[r12:HAS_QUESTION]->(q8)
CREATE (c)-[r13:HAS_QUESTION]->(q9)
CREATE (c)-[r14:HAS_QUESTION]->(q10)
CREATE (c)-[r15:HAS_QUESTION]->(q11)
CREATE (c)-[r16:HAS_QUESTION]->(q12)
CREATE (c)-[r17:HAS_QUESTION]->(q13)
return c,t,t1,q0,q01,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,r,r1,r2,r3,r4,r5,r6,r7,r8,r9,r0,r11,
r12,r13,r14,r15,r16,r17
答案 0 :(得分:2)
您使用的是哪个版本?
你能分享你的图表,以便我们可以重现这个问题吗?
我简化了您的查询,您可以试试这个吗?
MATCH (n:Question)<-[:HAS_QUESTION]-(c:Chapter)
WHERE id(c)=330 AND NOT(n:Removed)
MATCH (c)-[:HAS_CHILD]->(t:Topic)-[:HAS_QUESTION]->(qstn:Question)
WHERE NOT(qstn:Removed)
RETURN n,qstn
SKIP 0 LIMIT 10;
答案 1 :(得分:0)
我通过以下方式简化了我的查询..现在它正在运行,没有任何问题
START c = node({chapter_id})
OPTIONAL MATCH c-[r*..2]->(n:Question)
WHERE NOT(n:Removed)
RETURN DISTINCT n SKIP 0 LIMIT 10;