cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Multi-Path Results

Hi,

Neo4j - 3.5.12

In my project I need to find different paths. I have nodes in my graph database like below

  1. I want to find all the nodes having connections more than 1.
    I got it from getting the relationship count more than 1.
  2. From that node, find all the possible nodes that can reach that node and get the hop count. The output should be in the format of

G has more than 1 relationship, so
[E,F,G] hop=2
[H,G] hop=1

X has 3 relationship, so
[A,B,X] hop=2
[C,D,X] hop=2
[E,F,G,X] hop=3
and in the above collection, G has 2 relationship
so
[H,G,X] hop=2

and so on.

I haven't used any apoc procedure.

Appreciate your advance help.

1 REPLY 1

shan
Graph Buddy

Hi,

Perhaps you can use something like this:

match (target)
where size(()-->(target)) > 1
match p=((a)-[*..5]->(target))
with target, collect(distinct nodes(p)) as nodes
return *

You probably want to limit the length of the paths. In the query above, the limit is 5.
If you only care about paths that start from nodes with no incoming edge, you can use the query below:

match (source) where not ()-->(source)
with collect(distinct source) as sources
match (target)
where size(()-->(target)) > 1
unwind sources as source
match p=((source)-[*..5]->(target))
with target, collect(distinct nodes(p)) as nodes
return *

Cheers,
Seyed