Drawing a graph using d3js from neo4j/cypher json output

守給你的承諾、 提交于 2019-12-25 04:07:12

问题


Is it possible to return in a single cypher query distinct nodes and edges of a specific path. For instance, using the movies graph the query below return separately movies and actors, I'd like to return all nodes together. using path p = (...) and nodes(p) actually returns pairs of nodes regardless the use of distinct.

match (m:Movie {name: "Rain"}) -- (p:Person) return {nodes: collect(distinct {name: m.title}), actors: collect(distinct {name: a.name}), links: collect({source: m.title, target: a.name})}

Thanks in advance for any help, Pierre


回答1:


Got some help internally, so I'm sharing the answer. With neo'j 2.1.5, one can use unwind. The query following query returns in once the list of distinct nodes and distinct edges in the path - at least it worked with my examples:

match path = (p:Person {Name: 'Rain'})-[]-(m:Movie) unwind nodes(path) as p unwind rels(path) as r
return {nodes: collect(distinct p), links: collect(DISTINCT {source: id(startNode(r)), target: id(endNode(r))})}


来源:https://stackoverflow.com/questions/27348061/drawing-a-graph-using-d3js-from-neo4j-cypher-json-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!