0

Nodes :

Template -> Id =1 , Name = T1;
Segment -> Id =1 , Name = S1;
Segment -> Id =2 , Name = S2;

Relationships :

T1 - [r1:REL] -> S1;
T1 - [r2:REL] -> S2

Each relationship ( r1 and r2) has a property called LineIds which are integer array. Therefore, r1.LineIds = [1,3] and r2.LineIds = [1,2]

I am trying to get the intersection of both the LineIds.

I am trying to call apoc.coll.intersection() function using .Net driver Neo4jClient but it is throwing some or the other error. However, It is working in Neo4j Browser like

match (:Template)- [r1:REL] -> (m:Segment), (:Template) - [r2:REL] -> (n:Segment)
return apoc.coll.intersection(r1.LineIds, r2.LineIds) as result

Can somebody tell me the correct syntax in .net?

1 Answers1

0

You just call apoc the same way you call any other function:

var query = client.Cypher
    .Match("(:Template)-[r1:REL]->(m:Segment), (:Template)-[r2:REL]->(n:Segment)")
    .Return(() => new
    {
        result = Return.As <IEnumerable<int>> ("apoc.coll.intersection(r1.LineIds, r2.LineIds)")
    });

foreach(var result in query.Results)
{
    /* Do something here */
}
Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42
  • Thanks a lot. That actually worked very well. Also, what if I have more than two list to get the intersection from? How do I proceed in such case as apoc.coll.intersection only expects 2 arguments? Can you please let me know the syntax? – Vanshita Tilwani Mar 08 '18 at 09:04
  • You'll have to play around, my first guess would be to call intersection passing in the result of the other intersection, but I've not tested it. Try it and see, if you can't figure it out, add a new question with what you've tried and some sample data and someone should be able to help! – Charlotte Skardon Mar 08 '18 at 10:21
  • Yeah I did, finally figured it out. Thanks a lot – Vanshita Tilwani Mar 08 '18 at 12:36
  • Good I'm glad you got it sorted! You should accept answers if they've helped, so they might help others later on – Charlotte Skardon Mar 08 '18 at 15:09