Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I check if two nodes have relationship with each other,in neo4j embedded database in java?

How should I check if two nodes have relationship with each other,in neo4j embedded database in java?

I want the syntax please or a tutorial link,I have seen neo4j website but didn't find it.

Thanks.

like image 582
fereshteh Avatar asked Oct 20 '13 13:10

fereshteh


1 Answers

Given two nodes "nodeA" and "nodeB",

  1. gets all relationships attached to "nodeA",

    rels = nodeA.getRelationships();
    
  2. iterate through the collection of relationships "rels", for each relationship "rel", test whether the other end node is nodeB

    rel.getOtherNode(nodeA).equals(nodeB)
    
  3. if the above expression holds true for one of the relationships, then nodeA and nodeB are connected.

Here is the java API for "Node" and "Relationshiip",

http://api.neo4j.org/current/

like image 111
Lisa Li Avatar answered Sep 21 '22 05:09

Lisa Li