我有以下查询:
MATCH (d:Document)<-[o:OCCURS_IN]-(a:Alias)
WHERE LOWER(d.content) contains 'keyword'
WITH COUNT(o) as degree, a as a ORDER BY degree DESC LIMIT 20
MATCH (a)<-[:KNOWN_AS]-(ag:Agent)
RETURN ag;
我过滤包含关键字的所有Document节点,并按照它们连接到Document节点的频率排序前20个Alias节点。之后,将收集并返回连接到Alias节点的所有代理。
这给了我一组代理节点。除此之外,我想获得这组Agent节点中的所有关系。这意味着返回的节点集应该相同。只应添加这些节点之间的关系。
如果没有其他查询,我怎样才能实现这一目标?
答案 0 :(得分:3)
以下是如何在原始查询返回的所有Agent
节点之间获得之间的所有直接关系:
MATCH (d:Document)<-[o:OCCURS_IN]-(a:Alias)
WHERE LOWER(d.content) contains 'keyword'
WITH COUNT(o) as degree, a ORDER BY degree DESC LIMIT 20
MATCH (a)<-[:KNOWN_AS]-(ag:Agent)
WITH COLLECT(ag) AS ags
UNWIND ags AS ag1
UNIWND ags AS ag2
MATCH (ag1)-[r]->(ag2)
RETURN r;
答案 1 :(得分:1)
继续查询:
MATCH (d:Document)<-[o:OCCURS_IN]-(a:Alias)
WHERE LOWER(d.content) contains 'keyword'
WITH COUNT(o) as degree, a as a ORDER BY degree DESC LIMIT 20
MATCH (a)<-[:KNOWN_AS]-(ag:Agent)
OPTIONAL MATCH (ag)-[r]-()
RETURN ag, collect(r) as relationships