我对Cypher还是新手,我想知道在Neo4j Cypher中是否可能出现以下情况:

当我想询问从第一站到第四站应该乘坐什么公共汽车时,输出应该是(由最少数目的交汇处组成):
但并不是所有可能的组合:
谢谢!
发布于 2013-05-23 00:54:50
如果没有条件表达式(CASE/WHEN现在在2.0中),这是很困难的。这和我几分钟试过的时间一样近。您必须从结果关系集合中提取开始节点。
start st1=node:node_auto_index(name="station1"), st4=node:node_auto_index(name="station4")
match p=st1-[r*]->st4
with reduce(acc=[], route in rels(p):
case
when length(acc) > 0 and last(extract(a in acc: a.name)) = route.name then acc
else acc + route
end) as reducedRoutes
return reducedRoutes, length(reducedRoutes) as len
order by len;http://console.neo4j.org/r/koe6fo
https://stackoverflow.com/questions/16676476
复制相似问题