Help with Cypher queries and collections

12 views
Skip to first unread message

Daniele El-Jaick

unread,
Mar 2, 2015, 1:32:40 PM3/2/15
to ne...@googlegroups.com
Hi.

I have a very large graph where relationships have diferent types and a property Execution, that is an array of integers.
I need to return all different paths between generic node x and a node with property Cod = E9.
The problem is that I have to return paths with at least 1 equal number for Execution.
Like this:

NodeA -r1> NodeB -r2> NodeC -r3> Node E9

r1.Execution =[1, 2, 3, 4]
r2.Execution =[2, 5]
r3.Execution =[2, 7]

All of them have execution 2, then I have to return all path: NodeA -r1> NodeB -r2> NodeC -r3> Node E9

But If I have
r1.Execution =[1, 3, 4]
r2.Execution =[2, 5]
r3.Execution =[2, 7]

I just have to return NodeB -r2> NodeC -r3> Node E9

I tried this query:

1) MATCH p=(n)-[*]->(e:ENTITY{Cod: 'E9'}) WITH DISTINCT p RETURN (extract(n IN nodes(p)| n.Cod)) as Path, (extract(r IN relationships(p)| type(r))) as Rel

But this query does not filter property r.Execution

I did the same with paths that I know the lenght, like this:
I want to know all paths that envolved a node with cod = A6

NodeA -r1> Node Cod: A6 -r2> Node B

r1.Execution must be in r2.Execution

So I tried this query:

2) MATCH (e1:ENTITY)-[r1]->(a:ACTIVITY {Cod:'A6'})-[r2]->(e2:ENTITY) WHERE ANY (x IN r1.Execution WHERE x IN r2.Execution) RETURN  e1.Cod as Generated, e2.Cod as Consumed

But this query perform very, very, very, slow

In this case relationships are not a collection, just Execution is.

How can I filter Execution in query 1?

Is there a better way to do query 2?

Thanks a lot for any help!





Reply all
Reply to author
Forward
0 new messages