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.

Need help for this query

I need obtain the n most relevents nodes by degree, and its m most relevants neighbors. I found this solution (maybe isn't the optimal, but is working):

here, n and m are desired nodes count And asumme that exist in graph catalog a graph called test, wich has property degreeScore

match (s) with s, gds.util.nodeProperty('test', id(s), 'degreeScore') AS scoreSrc order by scoreSrc desc limit n

match (s)-[r]-(t) with s, t, r, scoreSrc, gds.util.nodeProperty('test', id(t), 'degreeScore') AS scoreDst order by scoreDst desc

with s, r, scoreSrc, collect(distinct [id(t), scoreDst, labels(t)[0]])[0..m] as tList

unwind tList as t

return distinct id(s) as idSrc, scoreSrc, labels(s)[0] as typeNodeSrc, type(r) as typeRel, t[0] as idDst, t[1] as scoreDs, t[2] as typeNodeDst

But, how can get most relevants nodes by level? Say, i need obtain n most relevants nodes, its m most relevants neighbors of 1st level and for each 1st level node neighbors , its p most relevants neighbors

1 ACCEPTED SOLUTION

The following should give you the top 10 nodes by 'degreeScore', with each node listed with its top 3 nodes by 'degreeScore' collected in a list.

You could use the same approach to extend to a third level.

match (s)
with s, gds.util.nodeProperty('test', id(s), 'degreeScore') AS scoreSrc
order by scoreSrc desc
limit 10
call {
with s
match (s)-[r]-(t)
with s, t, r, gds.util.nodeProperty('test', id(t), 'degreeScore') AS scoreDst
order by scoreDst desc
limit 3
return collect([r, id(t), scoreDst, labels(t)[0]]) as tList
}
return s, scoreSrc, tList

View solution in original post

2 REPLIES 2

The following should give you the top 10 nodes by 'degreeScore', with each node listed with its top 3 nodes by 'degreeScore' collected in a list.

You could use the same approach to extend to a third level.

match (s)
with s, gds.util.nodeProperty('test', id(s), 'degreeScore') AS scoreSrc
order by scoreSrc desc
limit 10
call {
with s
match (s)-[r]-(t)
with s, t, r, gds.util.nodeProperty('test', id(t), 'degreeScore') AS scoreDst
order by scoreDst desc
limit 3
return collect([r, id(t), scoreDst, labels(t)[0]]) as tList
}
return s, scoreSrc, tList

Thanks!!! Its work!!