You don't have to specify the max-length with shortest-path. Both your examples should work.
It is not an infinite loop, it is just O(n^2) so it will compute/check 2000^2 paths. On Thu, Dec 4, 2014 at 10:03 PM, grissimo <[email protected]> wrote: > Thanks, Michael. I also created the index on value :) > > For shortestPath, seems I have to specify the max depth, otherwise, it > won't work. *Presume that I don't know the max depth, how should this > work?* > MATCH p=shortestPath((e:Event { value:123 })-[:NEXT*]->(e2:Event { > value:200 })) > RETURN length(p) > > or > > MATCH p=shortestPath((e:Event { value:123 })-[*]->(e2:Event { value:200 })) > RETURN length(p) > > > > btw, without shortest path, it will easily go into infinite loop... > match p=(e:Event {value:123})-[:NEXT*0..2000]->(d2:Event {value:200}) > return length(p) > > Thanks, > Gris > > On Friday, December 5, 2014 9:15:31 AM UTC+13, Michael Hunger wrote: >> >> You shouldn't use neo4j console for tests like that. It is meant to be an >> in-memory sandbox for playing around or demoing small datasets (up to 200 >> nodes). >> That's why it has a hard request limit to not affect other sandboxes >> running on the same system. >> >> I'd change your first query to this >> >> WITH range(1,1000) AS Ids unwind Ids AS id MERGE (e:Event { value:id }) >> WITH COLLECT(e) AS events FOREACH (i IN range(0,length(events)-2)| >> FOREACH (e1 IN [events[i]]| >> foreach(e2 IN [events[i+1]]| CREATE UNIQUE (e1)-[:NEXT]->(e2)))) >> >> Then create an index: create index on :Event(value) >> >> Match the nodes first and then compute the path: >> >> MATCH (e:Event { value:123 }),(e2:Event { value:125 }) >> MATCH p=(e)-[:NEXT*0..150]->(e2) >> RETURN length(p) >> >> Even better use shortest-path for your query >> >> MATCH p=shortestPath((e:Event { value:123 })-[:NEXT*..150]->(e2:Event { >> value:200 })) >> RETURN length(p) >> >> Cheers, Michael >> >> >> On Thu, Dec 4, 2014 at 5:19 AM, grissimo <[email protected]> wrote: >> >>> Hi >>> I'm a newbie for neo4j, I've build up a linked list below: >>> >>> ------------------------------------ >>> WITH range(1,10000) AS Ids unwind Ids AS id >>> MERGE (e1:Event { value:id }) >>> >>> >>> MATCH (e:Event) >>> WITH COLLECT(e) as events >>> foreach (i in range(0,length(events)-2)| >>> foreach(e1 in [events[i]]|foreach (e2 in [events[i+1]]| >>> create unique (e1)-[:NEXT]->(e2)))) >>> ------------------------- >>> >>> >>> I tried with below query in http://console.neo4j.org/ but came up with >>> error as follow. >>> Error: org.neo4j.kernel.guard.GuardOperationsCountException: max ops ( >>> ops=1000001) >>> >>> MATCH p=(e:Event { value:123 })-[:NEXT*0..150]->(e2:Event { value:125 }) >>> RETURN length(p) >>> >>> Obviously, this is not a good way for doing this. >>> >>> What I really want is to get the path depth between two specific nodes >>> with NEXT relationship. >>> >>> MATCH p=(e:Event { value:123 })-*[:NEXT*]*->(e2:Event { value:125 }) >>> RETURN length(p) >>> >>> >>> or assumed that I created a time tree(as here >>> <http://www.markhneedham.com/blog/2014/04/19/neo4j-cypher-creating-a-time-tree-down-to-the-day/>), >>> and series of event with (event)-[:HAPPONED_ON->(d:Day), I want to >>> calculate how many days between these two days. >>> >>> Is there a correct/good way to calculate the path depth? >>> >>> >>> Regards >>> >>> >>> -- >>> 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. >>> >> >> -- > 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. > -- 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.
