Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-16-2022 10:14 AM
Hi, I am currently writing a query to get results by path matching. The relationships between the nodes have weights and i want to sum them up and divide them by the number of relationships in one single path.
Solved! Go to Solution.
08-16-2022 11:18 AM - edited 08-16-2022 11:34 AM
Can you post the actual query?
In the meantime, I will provide you with a potential approach you can apply. You can use the 'reduce' method to sum up the weights of each relationship along each path. Of course, change the match to meet your path requirements.
match p=()-[:REL*]->()
return reduce(sum=0, x in relationships(p) | sum + x.weight) as sum
08-16-2022 11:18 AM - edited 08-16-2022 11:34 AM
Can you post the actual query?
In the meantime, I will provide you with a potential approach you can apply. You can use the 'reduce' method to sum up the weights of each relationship along each path. Of course, change the match to meet your path requirements.
match p=()-[:REL*]->()
return reduce(sum=0, x in relationships(p) | sum + x.weight) as sum
08-16-2022 01:56 PM
It seems that my query worked just fine and i made a mistake with the weights. My original approach was:
Match (s) where ID(s) = 2 Match (s)-[rel1:is_a]->(:GeneralPersonType)
<-[rel2:is_related_to]-(:GeneralCourseType)<-[rel3:is_a]-(x:Course)
with rel1.weight + rel2.weight + rel3.weight as result return result
I tried your query and it also works just fine for me so thank you very much for your quick reply!
All the sessions of the conference are now available online