Maurizio Cimino
Maurizio Cimino

Reputation: 135

Cypher query: match all the couples of nodes iff they share a relationship with a specific property

I build a very simple graph having different type of nodes and just one type of relationship, named MAPPING1TO1. Then, each couple of nodes share the same type of relationship. MAPPING1TO1 have just one property, named EventoTag. This property is an array of strings formatted as follows: (n,m), where n is a three or two-digit integer number, and is m a two-digit integer number. So, for example, given a generic relationship r, its property EventoTag might looks like: (001,11), (002,12), (003,13), ...

I would write a query in Cypher that returns all the couples of nodes sharing a relationship that satisfy the following condition: given a string x in input, there exists a string inside the array property EventoTag that contains x as a substring.

I tried to solve this problem with the following query:

WITH "912" AS event 
MATCH p=(a)-[r]->(b)
WHERE ALL(item in r.EventoTag WHERE SUBSTRING(item,0,4) CONTAINS event)
RETURN p

The query "works", but takes too much. I have got relationships that are not right, i.e. does not satisfy the condition above. To make an example, look the following image of the result:

enter image description here

The selected relationship is wrong, while the others are right. It is wrong because it does not satisfy the condition (its EventoTag property does not contain the substring "912"), but still it is taken in the final result, and I don't understand why.

Can you help me? Thank you.

Upvotes: 0

Views: 227

Answers (1)

InverseFalcon
InverseFalcon

Reputation: 30397

This is likely due to the Neo4j Browser feature that takes all the nodes returned by a query, and finds and fills in all the relationships that exist between them (regardless of whether you returned those relationships or not).

From the Browser Settings (gear icon in the lower left), scroll to the bottom and uncheck "Connect result nodes". If you re-run your query most likely the relationship will not be returned.

Upvotes: 2

Related Questions