【发布时间】:2015-07-23 00:03:23
【问题描述】:
我正在尝试查询主题节点周围一定距离的邻域。扭曲的是,我不想遵循具有特定属性的节点的关系。任何查询都需要在数百万个节点和边的图上运行(这排除了收集路径)。
我想我有一个可以做到的查询:
MATCH (topic: attribute)-[r:describedBy|influences*0..2]-(n: attribute)
WHERE id(topic) IN [239930]
WITH n, r as rels, topic
MATCH (n: attribute)-[r:describedBy|influences]->()
WHERE NOT n.key in ['enrichment', 'classification'] AND r in rels
WITH n, r, collect(r) as rels, topic
MATCH path = shortestpath((topic)-[*..2]-(n))
WHERE extract(rel IN rels(path) | rel) as r WHERE r in rels
WITH r, extract(n IN nodes(path) | n) as nodes
RETURN count(DISTINCT r), count(DISTINCT nodes)
问题是试图比较关系的集合。具体来说:
Type mismatch: expected Collection<Collection<Relationship>> but was Collection<Relationship> (line 8, column 43 (offset: 369))
"WHERE extract(rel IN rels(path) | rel) in rels "
我在多次尝试创建此查询时遇到了这个“关系集合的集合”问题。
我该如何 A:修复 collection of collection of relationships 问题或 B:重写查询,使其返回给定距离的一个或多个节点周围的邻域,而不遵循具有特定属性的节点的关系?
[编辑]
根据@cybersam 的建议,现在的查询是:
WHERE NOT n.key in ['enrichment', 'classification'] AND r in rels
WITH n, r, collect(r) as rels, topic
MATCH path = shortestpath((topic)-[*..2]-(n))
WHERE [r2 IN rels(path) WHERE r2 in rels]
WITH r, extract(n IN nodes(path) | n) as nodes
RETURN count(DISTINCT r), count(DISTINCT nodes)
问题是这会返回 47242 条关系和 47242 条边。看起来它是从路径集合返回边,而不是从上面的子查询中返回(从之前的实验中,它的边数大约为 100103)。
【问题讨论】: