neo4j - Cypher: Return path where begin and end may be equal -


i have taxonomy neo4j graph. basic structure this:

taxonomyname -has_root_term-> root -is_broader_than-> term -is_broader_than-> term'-is_broader_than-> term'' - ... 

now want given term - e.g. term'' - path taxonomy root (or multiple paths; please note there may multiple taxonomies multiple eligible roots, structure poly-hierarchy):

start n=node:index("id:term''id") match p = taxonomy-[:has_root_term]->r-[:is_broader_than*]->n return tail(extract(n in nodes(p) : n.id)) 

the tail excludes first node don't taxonomy node itself. works fine, except when directly query root term. nothing returned. of course: search path @ least 3 elements, taxonomy node, root node , descendant of root. i'd need express r , n may equal. tried make is_broader_than relationship optional, null returned because pattern cannot found.

so how restrict query paths including root term , allowing paths of length one, containing root term?

thank you!

typical "rtfm" case, i'm afraid ;-)

the documentation @ http://docs.neo4j.org/chunked/stable/query-match.html#match-zero-length-paths tells us, that

... root -[:is_broader_than*0..]-> term ... 

does trick. specifying asterisk assumes 1.. range. 0.., start , end node may same, i.e. relationship may not have been traversed @ all.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -