我有这个表达:
MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)<-[:Belong]-(h:GNE)
WITH h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info
ORDER BY score DESC
WHERE score >= 4
RETURN h.sym, score, info, h.chr
所以,我想添加更多跟随模式,就像这句话:
(c:CLUSTER)-[:has]-(v:ORTH) where v.Term are equal in all CLUSTER
有什么建议吗? 谢谢!
答案 0 :(得分:1)
通过其他参数过滤结果:
MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)<-[:Belong]-(h:GNE)
WITH h, c
MATCH (c:CLUSTER)-[:has]-(v:ORTH{term:"Your Value"})
WITH h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info
ORDER BY score DESC
WHERE score >= 4
RETURN h.sym, score, info, h.chr
如果你真的希望v.term的所有值都相同(但你不知道该值是提前的那个)那么它会更多地涉及到我认为你将不得不使用WHERE ALL集合谓词,用于比较ORTH节点集合中的term属性。
MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)<-[:Belong]-(h:GNE)
WITH h, c
MATCH (c:CLUSTER)-[:has]-(v:ORTH)
WITH h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info, COLLECT(v) as orths
ORDER BY score DESC
WHERE ALL(orth IN TAIL(orths) WHERE (orth.term = HEAD(orths).term))
AND score >= 4
RETURN h.sym, score, info, h.chr
如果这是您想要的,将HEAD和TAIL集合修饰符分解为单独的WITH并首先应用长度过滤器可能会更快:
MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)<-[:Belong]-(h:GNE)
WITH h, c
MATCH (c:CLUSTER)-[:has]-(v:ORTH)
WITH h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info, COLLECT(v) as orths
WHERE score >= 4
WITH h, score, info, TAIL(orths) as orhttail, HEAD(orths) as orthhead
WHERE ALL(orth IN orthtail WHERE (orth.term = orthead.term))
RETURN h.sym, score, info, h.chr
答案 1 :(得分:0)
这是一个未经考验的建议。
MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER)<-[:Belong]-(h:GNE)
WITH h, c
MATCH (c:CLUSTER)-[:has]-(v:ORTH)
WITH v, h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info
WHERE v.Term are equal in all CLUSTER
ORDER BY score DESC
WHERE score >= 4
RETURN h.sym, score, info, h.chr
可替换地:
MATCH (g:GNE{sym:"ST1"})-[:like]->(c:CLUSTER) // Find 'c', we don't need 'g' after this
WITH c
MATCH (v:ORTH)-[:has]-(c:CLUSTER)<-[:Belong]-(h:GNE) // From 'c', find the datums of interest
WITH v, h, COUNT(c) AS score, COLLECT(c.clusterInfo) AS info
WHERE v.Term are equal in all CLUSTER
ORDER BY score DESC
WHERE score >= 4
RETURN h.sym, score, info, h.chr