简体   繁体   中英

Cypher Query, make a where by several nodes properties if they have the same type of relationship

If we have a node related with other nodes by the same type of relationship

classmetadata<-INSTANCE_OF-instance(TheNodeINeed)-RELATED_TO->...................

 - ->listype(The owner(name=d,etc))
 - ->listype(The state(name=x,etc))
 - ->listype(The propertie(name=y,etc))
 - ->listype(The location(name=z,etc))

The instance node to find, must be looking by a node classmetadata within a index by its name(this is easy) and instance name (this is easy too) and also by the listype .name=.. and listype .name=.. and listype .name=.. and here is the problem:

If I try looking just for the instance with name MyInstance who is RELATED_TO a owner with name d , here I only quering about one listype node there's no problem, this query works

START classmetadata = node:classes(name = "MyClassMetadata")
MATCH classmetadata<-[:INSTANCE_OF]-instance-[:RELATED_TO]->listype
WHERE instance.name="MyInstance" and listype.name = "d"
RETURN instance, listype
ORDER BY instance.name ASC skip 0 limit 10

but if I need to look for the instance with name MyInstance who is RELATED_TO a owner with name d and is also RELATED to state with name x and is also RELATED to propertie with name y there is a problem the query result is always empty, is there any way to filter about two o three or more nodes.properties(listype.name) at same time if they are related by the same type of relatioship?

something like this is not working

START classmetadata = node:classes(name = "MyClassMetadata")
MATCH classmetadata<-[:INSTANCE_OF]-instance-[:RELATED_TO]->listype
WHERE instance.name = "MyInstance" AND listype.name = "x"
AND listype.name = "y" AND listype.name="d" RETURN instance, listype
ORDER BY instance.name ASC skip 0 limit 10

I added the name property to each relationship in order to be sure that I am making the filtering in the right node.

START classmetadata = node:classes(name = "MyClassMetadata")
MATCH classmetadata<-[:INSTANCE_OF]-instance-[r1:RELATED_TO]->listype1,
instance-[r2:RELATED_TO]->listype2, 
instance-[r3:RELATED_TO]->listype3 

WHERE instance.name = "MyInstance" AND 
r1.name="state" AND listype1.name = "x" AND 
r2.name="property" AND listype2.name = "y" AND 
r3.name="owner" AND listype3.name="d" 
RETURN instance, listype
ORDER BY instance.name ASC skip 0 limit 10

So you want to find all listypes where the name property of listtype can be d or x or y (in your first code snippet)? If so, then START classmetadata = node:classes(name = "NodeType ") MATCH classmetadata<-[:INSTANCE_OF]-instance-[:RELATED_TO]->listype WHERE instance.state="good" and (not(listype.name in ["d","x","y"])) RETURN instance, listype ORDER BY instance.name ASC skip 0 limit 10

Your query above too would work...just refer to listtype uniformly- no need for listtype1, listtype2 etc. START classmetadata = node:classes(name = "NodeType ") MATCH classmetadata<-[:INSTANCE_OF]-instance-[:RELATED_TO]->listype WHERE instance.state="good" and AND listype.name! =~ ". Po. " AND listype.name! =~ ". Me. " RETURN instance, listype ORDER BY instance.name ASC skip 0 limit 10

Is that what you're looking for?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM