neo4j:使用CONSTRAINT提取随机图

时间:2018-01-09 15:06:50

标签: neo4j cypher neo4j-apoc

为了提取随机图,我使用:

// assume already matched to start node n
MATCH r = (n)-[:I]-()
WITH apoc.coll.randomItems(collect(r), 10) as r1
UNWIND r1 as r
WITH r1, last(nodes(r)) as n

MATCH r = (n)-[:I]-()
WITH r1, apoc.coll.randomItems(collect(r), 10) as r2
UNWIND r2 as r
WITH r1, r2, last(nodes(r)) as n

MATCH r = (n)-[:I]-()
WITH r1, r2, apoc.coll.randomItems(collect(r), 10) as r3
UNWIND r3 as r
WITH r1, r2, r3, last(nodes(r)) as n

MATCH r = (n)-[:I]-()
WITH r1, r2, r3, apoc.coll.randomItems(collect(r), 10) as r4
RETURN r1 + r2 + r3 + r4

但我想添加一个约束:

MATCH r = (n)-[z:I]-()
WHERE z.grow CONTAINS "xxx"
WITH apoc.coll.randomItems(collect(r), 10) as r1

但它不起作用。事实上,它就像没有约束一样。

此外,

MATCH r = (n)-[:I]-()
WHERE r.grow CONTAINS "xxx"
WITH apoc.coll.randomItems(collect(r), 10) as r1

不明白。

可以添加这样的约束吗?

0 个答案:

没有答案