2

目前我使用以下 Cypher / APOC 查询TO通过某个属性(userid )搜索关系类型:

CALL apoc.index.relationships('TO','user:16c01100-aa92-11e3-a3f6-35e25c9775ff') YIELD rel, start, end
WITH DISTINCT rel, start, end
MATCH (ctx:Context)
WHERE rel.context = ctx.uid 
ETURN DISTINCT start.uid AS source_id,
start.name AS source_name,
end.uid AS target_id,
end.name AS target_name,
rel.uid AS edge_id,
ctx.name AS context_name,
rel.statement AS statement_id,
rel.weight AS weight;

我希望不仅可以搜索索引TO,还可以搜索索引ATAT关系类型),以便生成的rel参数同时包含TOAT关系。

我想这就像添加一个OR运算符一样简单,如下所示:

CALL apoc.index.relationships('TO','user:16c01100-aa92-11e3-a3f6-35e25c9775ff') OR
apoc.index.relationships('AT','user:16c01100-aa92-11e3-a3f6-35e25c9775ff') YIELD rel, start, end
WITH DISTINCT rel, start, end
MATCH (ctx:Context)
WHERE rel.context = ctx.uid
RETURN DISTINCT start.uid AS source_id,
start.name AS source_name,
end.uid AS target_id,
end.name AS target_name,
rel.uid AS edge_id,
ctx.name AS context_name,
rel.statement AS statement_id,
rel.weight AS weight;

但它不起作用...

也许我可以做一些事情,我rel从这两个apocs 中获取 s,然后简单地将它们合并为一个rel,但我真的不知道如何做到这一点......或者也许有一种更简单的方法我没有看到?

4

2 回答 2

1

UNION子句的使用怎么样:

CALL apoc.index.relationships('TO','user:16c01100-aa92-11e3-a3f6-35e25c9775ff') YIELD rel, start, end
WITH DISTINCT rel, start, end
MATCH (ctx:Context)
WHERE rel.context = ctx.uid
RETURN DISTINCT start.uid AS source_id,
start.name AS source_name,
end.uid AS target_id,
end.name AS target_name,
rel.uid AS edge_id,
ctx.name AS context_name,
rel.statement AS statement_id,
rel.weight AS weight
UNION
CALL apoc.index.relationships('AT','user:16c01100-aa92-11e3-a3f6-35e25c9775ff') YIELD rel, start, end
WITH DISTINCT rel, start, end
MATCH (ctx:Context)
WHERE rel.context = ctx.uid
RETURN DISTINCT start.uid AS source_id,
start.name AS source_name,
end.uid AS target_id,
end.name AS target_name,
rel.uid AS edge_id,
ctx.name AS context_name,
rel.statement AS statement_id,
rel.weight AS weight
于 2018-02-21T12:08:21.093 回答
0

您可以使用运行密码片段来做到这一点:

WITH '16c01100-aa92-11e3-a3f6-35e25c9775ff' as userId

CALL apoc.cypher.run("
     CALL apoc.index.relationships('TO','user:' + $id) YIELD rel
     RETURN rel
", {id: userId}) YIELD value
WITH userId, collect(value.rel) as r1

CALL apoc.cypher.run("
     CALL apoc.index.relationships('AT','user:' + $id) YIELD rel
     RETURN rel
", {id: userId}) YIELD value
WITH r1, collect(value.rel) as r2

UNWIND (r1 + r2) as rel
WITH rel, nodeStart(rel) as start, nodeEnd(rel) as end
MATCH (ctx:Context)
WHERE rel.context = ctx.uid
RETURN DISTINCT start.uid AS source_id,
                start.name AS source_name,
                end.uid AS target_id,
                end.name AS target_name,
                rel.uid AS edge_id,
                ctx.name AS context_name,
                rel.statement AS statement_id,
                rel.weight AS weight;
于 2018-02-21T14:09:19.593 回答