praveen gottam
praveen gottam

Reputation: 43

How do i get all nodes in the graph on a certain relation ship type

I have build a small graph where all the screens are connected and the flow of the screen varies based on the system/user. So the system/user is the relationship type.

I am looking to fetch all nodes that are linked with a certain relation ship from a starting screen. I don't care about the depth since i don't know the depth of the graph. Something like this, but the below query takes ever to get the result and its returning incorrect connections not matching the attribute {path:'CC'}

match (n:screen {isStart:true})-[r:NEXT*0..{path:'CC'}]-() return r,n

Upvotes: 1

Views: 71

Answers (1)

cybersam
cybersam

Reputation: 67044

A few suggestions:

  1. Make sure you have created an index for :screen(isStart):

    CREATE INDEX ON :screen(isStart);
    
  2. Are you sure you want to include 0-length paths? If not, take out 0.. from your query.
  3. You did not specify the directionality of the :NEXT relationships, so the DB has to look at both incoming and outgoing :NEXT relationships. If appropriate, specify the directionality.

  4. To minimize the number of result rows, add a WHERE clause that ensures that the current path cannot be extended further.

Here is a proposed query that combines the last 3 suggestions (fix it up to suit your needs):

MATCH (n:screen {isStart:true})-[r:NEXT* {path:'CC'}]->(x)
WHERE NOT (x)-[:NEXT {path:'CC'}]->()
return r,n;

Upvotes: 1

Related Questions