I'm trying to create my own function for neo4j that recursively goes through a graph and returns any nodes and edges that are connected to an edge with a long value greater than 100.
I know there is a simple CYPHER query for it but by doing this, I can know how to proceed with more complex stuff on my own.
pseudocode
- get all relations from node matching Id where the relationship is type 'TypeExample'.
- if the relation has a long property "Count" and Count > 100, go to 1.
IF 5 nodes deep, stop. return list of nodes and edges with interface IPath.
package example; import java.util.Iterator; import java.util.stream.Stream; import java.util.stream.StreamSupport; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.ResourceIterator; import org.neo4j.logging.Log; import org.neo4j.procedure.*; import org.neo4j.procedure.Description; import org.neo4j.procedure.Name; import java.util.List; import java.util.Map; import java.util.Set; import org.neo4j.graphdb.index.Index; import org.neo4j.graphdb.index.IndexManager; public class NodeFinder { @Context public GraphDatabaseService db; @Context public Log log; @Procedure @Description("finds Nodes one step away") public Stream<SomeList> GetRelations(@Name("nodeId") long nodeId, @Name("depth") long depth, @Name("rel") String relType) { Recursive(nodeId); //return list of Nodes and Edges } private void Recursive(long id) { Node node = db.getNodeById(nodeId); Iterable<Relationship> rels = node.getRelationships(); for (Relationship rel : rels) { long c = (long) rel.getProperty("Count"); if (c > 100) { Recursive(rel.getEndNodeId()); } } } }