Cypher query to get shortest path between A and B that doesn't go through C, that isn't massively slow? Or recommend alternative to Cypher/Neo4j -
i'm working graph has thousands of nodes. have person nodes, , friends relationships between them. e.g., gus-[:friends]-skylar
if wanted find shortest friend path between hank , gus long they're not separated more 20 rels, this:
start hank=node(68), gus=node(66) match p = shortestpath((hank)-[:friends*..20]-(gus)) return p
this works , fast, when found shortest path of length 10 or more.
but wanted find path hank gus does not go through glenn?
the query i've tried this:
start hank=node(68), gus=node(66), glenn=node(59) match p =(hank)-[:friends*..20]-(gus) not glenn in nodes(p) return p order length(p) limit 1;
this works on small graphs (30 or people), if there 1000's...the jvm runs out of heapspace.
so i'm guessing cypher finds all paths between gus , hank of length 20 or less, , applies filter? it's clear why slow.
in abstract sense, algorithm should doable same big o runtime, because change check make sure each node (as search) isn't 1 want avoid.
any suggestions how accomplish this? i'm pretty new cypher.
if not possible cypher, can recommend other database , graph language "stack"?
thanks
can test performance of following query? main difference compares paths instead of nodes. i've added direction in paths well, speed query.
start hank=node(68), gus=node(66), glenn=node(59) match p = allshortestpaths((hank)-[:friends]->(gus)) collect(p) guspaths, hank, glenn match p2 = allshortestpaths((hank)-[:friends]->(glenn)) collect(p2) glennpaths, guspaths filter(x in guspaths none (x2 in glennpaths x = x2)) filtered return filtered order length(filtered) limit 1
Comments
Post a Comment