The traversal API returns paths. So if you are calling "nodes" on it should be repeating nodes over and over. I think you just need to return the endNode.
Also there is an implementation of wcc on https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/4cdc97c2d4e42b91e6281965e424c3b2624c9f99/src/main/java/apoc/algo/WeaklyConnectedComponents.java#L37 you can take a look at. On Friday, January 20, 2017 at 12:28:35 PM UTC-6, Felix Dietze wrote: > > Hi, > > I'd like to know if its possible to do a faster traversal than in this > stored procedure. > > I want to return all reachable (directed) nodes from a startnode: > > public class ConnectedComponent { > @Context > public GraphDatabaseService graphDatabaseService; > > > private static enum RelTypes implements RelationshipType { > CONNECTS > } > > > @Procedure(value = "connectedComponent") > public Stream<Visited> connectedComponent(@Name("start") Node start) { > return graphDatabaseService.traversalDescription() > .depthFirst() > .relationships( RelTypes.CONNECTS, Direction.OUTGOING ) > .uniqueness( Uniqueness.RELATIONSHIP_GLOBAL ) > .traverse( start ) > .nodes().stream().map(Visited::new); > } > > > public static class Visited { > public final Node node; > public Visited(Node node) { > this.node = node; > } > } > } > > > I call the procedure like this: > match (n:Post {id: "3235"}) CALL connectedComponent(n) yield node return > node; > > > This takes around 3 seconds for 15k visited nodes. That's about 10x slower > compared to a stored procedure in postgres on the same data. Any ideas? > > > > Thank you! > > -- You received this message because you are subscribed to the Google Groups "Neo4j" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
