Cypher Simple Paths

201 views
Skip to first unread message

Rehan

unread,
Oct 9, 2012, 6:15:25 AM10/9/12
to ne...@googlegroups.com
Hi, 

I am using below query to get all possible paths between two nodes:

START a=node:node_auto_index(name="A") , m=node:node_auto_index(name="M")  MATCH p=a-[*]-m  WHERE ALL(r in RELS(p) WHERE (r.value >= 200 OR r.value=0) ) RETURN p ORDER BY length(p) desc limit 20

This query returns the results with loops as well i.e. paths contains loop. How can I restrict  this to return only simple paths. 

Br , 

Rehan

Rehan

unread,
Oct 9, 2012, 6:20:39 AM10/9/12
to ne...@googlegroups.com
UpDate: 

My Nodes have multiple relationships of same type with each other. 

Peter Neubauer

unread,
Oct 9, 2012, 10:38:02 AM10/9/12
to ne...@googlegroups.com
You could for instance exclude paths that have m or a as one of the
nodes? http://docs.neo4j.org/chunked/snapshot/query-function.html#_collection_functions

Let me know if you need an example, I think I can craft one ...

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html
> --
>
>

Rehan Azher

unread,
Oct 9, 2012, 11:26:28 PM10/9/12
to ne...@googlegroups.com
Hi Peter, 

Can you help t craft one such query. please. 


Thanks and Best Regards,


--
Rehan Azher
Cell: +65 92967887


--



Wes Freeman

unread,
Oct 10, 2012, 3:54:21 AM10/10/12
to ne...@googlegroups.com
This is a bit of an abomination--there should be a better way--but you might be able to use it to get simple paths:


If you want to see the cyclic paths, take out the where clause.

Wes

--
 
 

Rehan

unread,
Oct 10, 2012, 11:43:47 PM10/10/12
to ne...@googlegroups.com


Thanks WES, what if we want to add a filter on relationship as well. i.e. property with value <=200.

Wes Freeman

unread,
Oct 11, 2012, 5:07:11 AM10/11/12
to ne...@googlegroups.com
You could add that in to the WHERE clause with an AND, just like you had it in the original query.

Wes

--
 
 

Rehan

unread,
Oct 11, 2012, 9:46:34 PM10/11/12
to ne...@googlegroups.com
Hi Wes, 

Thank you . 

One more query is it possible to build a query which should not include a given path . 

Thanks and Best Regards, 

Rehan

Wes Freeman

unread,
Oct 11, 2012, 10:11:25 PM10/11/12
to ne...@googlegroups.com
Probably. The question is, how do you know which path you don't want to include?

--
 
 

Wes Freeman

unread,
Oct 11, 2012, 10:27:06 PM10/11/12
to ne...@googlegroups.com
You can do something like this, which is pretty straightforward:
Reply all
Reply to author
Forward
0 new messages