Ninja
Ninja

Reputation: 5142

Match nodes of variable depth

I have users who like different geographies (could be a country, state or city) and I want to match those users who like geographies in the same country.

For eg.

user A likes USA 
user B likes USA
user C likes San Jose
user D likes France

then I want user A to be matched to users B and C.

Node relationships in my graph

What cypher query will get me the results? This is what I tried:

/** node id of user A is 0 **/

START u=node(0) MATCH (u:users) - [:likes] - (g1) - [:contains*0..5] - (g2) - [:likes] - (o:users) RETURN o;

This query is not working as expected. What would be a right syntax?

Upvotes: 0

Views: 50

Answers (1)

tkroman
tkroman

Reputation: 4798

If I understood you correctly, something like this might work in your case. But pay attention - there might be certain issues in case of circular paths.

The main idea behind this is setting not only relationships but their directions as well.

Upvotes: 2

Related Questions