Is it possible to filter by list with order in neo4J cypher

cypher
knowledge-base

(Zakahili) #1

Is it possible to order and filter by relation in neo4j ? for example :

I have gardien and kid with relations (father,mother,brother, sister) and I want to list gardiens and kids with their relationships with this type of filter:

if the gardien is the father of the kid: 
   then return (father, kid)
else if the kid doesn't have the father :
   then return his (mother, kid)
else if the kid doesn't have the father or mother:
   then return his (brother, kid)
otherwise :
   return his (sister, kid)

How can do a request like this with cypher ?

Thank you in advance,


(M. David Allen) #2

Yes, you can do all of this. I can't show you what the cypher would look like because you need a data model for that, but I can point you in the right direction.

You can use the OPTIONAL MATCH in cypher to assert that a pattern may or may not exist. So for example something like matching a child node, and then creating an OPTIONAL MATCH to a father or a mother.

You can use CASE ... WHEN expressions in cypher to do the if/then/else part of your query.