Olga Mu
Olga Mu

Reputation: 916

Cypher Order By Number of Paths

Let's say I have a graph of movies and directors, where movies are connected to each other by co-viewership. I want to find similar directors, i.e. directors whose films tend to be watched together.

START n=node:index(Name="Steven Spielberg") MATCH n-->m--l<--o RETURN o;

This gets me all of the related directors, but how do I order them by the number of paths that connect them? Bonus points if I can also take weight of the tie between films into consideration.

Upvotes: 3

Views: 526

Answers (2)

Michael Hunger
Michael Hunger

Reputation: 41676

count(*) is the number of paths that start with n and end with o

START n=node:index(Name="Steven Spielberg") 
MATCH n-->m--l<--o 
RETURN o,count(*)
order by count(*) desc;

with weights on the relationships

START n=node:index(Name="Steven Spielberg") 
MATCH path=n-->m--l<--o 
RETURN o,sum(reduce(sum=0,r in rels(path) : sum+r.weight)) as weight
ORDER BY weight desc;

Upvotes: 4

Gopi
Gopi

Reputation: 10293

START n=node:index(Name="Steven Spielberg") 
MATCH path=n-->m--l<--o 
RETURN o
ORDER BY length(path);

Upvotes: 0

Related Questions