Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-31-2022 03:55 PM
match (n:Movie), (m:Person)
CALL apoc.path.expandConfig(n, {
relationshipFilter:"",
minLevel: 1,
maxLevel: 4,
uniqueness: "NODE_PATH"
})
YIELD path
WITH [x in nodes(path) | x.name] AS nodes,
[a in relationships(path) |type(a)] as relationships
return nodes, relationships
RETURNS something like this.
[null,"Joel Silver",null,"Andy Wachowski"] │["PRODUCED","PRODUCED","WROTE"]
05-31-2022 08:17 PM
You are not using the Person match (m) in this case. The Cartesian product of n and m, will cause each movie node to be identically processed multiple time equal to the number of Person nodes in your database. Removing it from the match should greatly improve performance and reduce the redundant data returned.
What is the format of the output you are looking for?
06-07-2022 07:37 PM
something like x- causes -y-causes-z-causes-w.
now i am getting
{x|y|z|w} | {causes|causes|causes}
notice how they are in separate
06-07-2022 09:01 PM - edited 06-07-2022 09:03 PM
Ok, this may be a little out there. I tested it on a graph I have and it worked. For each path, it will format the path as follows, where the name is output as a name or title, depending on if the node is a person or movie, respectively. Of course, you can change the query to output the specific property from each node that you want.
movie_title <-> RELATIONSHIP_TYPE <-> node(name or title) <-> RELATIONSHIP_TYPE <-> ...
match (n:Movie)
CALL apoc.path.expandConfig(n, {
relationshipFilter:"",
minLevel: 1,
maxLevel: 4,
uniqueness: "NODE_PATH"
})
YIELD path
with relationships(path) as relationships
with startNode(head(relationships)) as headNode, tail(relationships) as tail
return reduce(s=headNode.title, r in tail | s + " <-> " + type(r) + " <-> " + coalesce(endNode(r).name, endNode(r).title)) as path
Let me know how it goes.
All the sessions of the conference are now available online