0

I have a model in Graph theory of Movies and Actors. The relation between the two is "requires". The graph is shown below. A and B are Movies. 1,2,3,4,5,6 are actors. Movie A requires 1,2,3,4 actors. Movie B requires 4,5,6 actors. We can see that 4 is shared among both movies.

Current Query:

MATCH (m :Movie) -[r :require]-> (a :actor)
RETURN m,r,a;
Current Output

Current Output

Expected Output

I want to display something as below. Here actor 4 is shown once for each movie. Can someone help me fix this ?

Expected Output

Shreya B
  • 305
  • 2
  • 14

2 Answers2

1

The visualization logic in Neo4j Browser displays each node only once, therefore you cannot get node 4 two times. A workaround would be using the neo4j APOC library and return virtual nodes as copies of the blue nodes instead of the real node. If you create two virtual nodes out of node 4, the UI considers them being distinct and therefore show two nodes.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
  • Ok. Thank you @Stefan Armbruster. Using library inside neo4j.conf file gives me some error. – Shreya B Apr 26 '21 at 16:34
  • Once you have APOC installed, something like this should deliver what you want: `MATCH (m :Movie) -[r :require]-> (a :actor) WITH m, r, apoc.create.vNode(labels(a), apoc.any.properties(a)) as a2 RETURN m, apoc.create.vRelationship(m, type(r), {}, a2), a2;` – Stefan Armbruster Apr 27 '21 at 20:37
0

You can do that my grouping the actors by movie and end up with a row of movie, [list of actors ]

MATCH (m:Movie)-[r:require]->(a :actor)
WITH m collect(a) as actors
return m,actors
cechode
  • 1,002
  • 1
  • 8
  • 20