如何在Neo4J 3.x中构建Cypher/APOC查询,该查询搜索两种不同的关系类型?
目前,我使用以下Cypher/APOC查询按特定属性(如何在Neo4J 3.x中构建Cypher/APOC查询,该查询搜索两种不同的关系类型?,neo4j,cypher,neo4j-apoc,Neo4j,Cypher,Neo4j Apoc,目前,我使用以下Cypher/APOC查询按特定属性(userid)搜索关系类型to: 我希望不仅可以搜索索引to,还可以搜索索引AT(AT类型的关系),以便生成的rel参数同时包含to和AT关系 我可以想象它会像添加或操作符一样简单,如下所示: CALL apoc.index.relationships('TO','user:16c01100-aa92-11e3-a3f6-35e25c9775ff') OR apoc.index.relationships('AT','user:16c0110
user
id)搜索关系类型to
:
我希望不仅可以搜索索引to
,还可以搜索索引AT
(AT
类型的关系),以便生成的rel
参数同时包含to
和AT
关系
我可以想象它会像添加或操作符一样简单,如下所示:
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;
但它不起作用
也许我可以做点什么,从这两个apoc中得到rel
s,然后简单地把它们合并成一个rel
,但我真的不知道怎么做。。。或者也许有一种更简单的方法我看不出来?子句的用法如何:
您可以通过以下方式完成:
工作得很有魅力。非常感谢。
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;
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
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;