Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

path - Neo4j: How to return nodes which have a specific node in common?

I am wondering how to return all the nodes with Label_C which have at least one node with LABEL_A in common if the number of the output nodes connected to such a node with LABEL_A is greater than or equal to a threshold. The target node can thus be reached through a path from any of the desired output nodes.

The structure is (common:Label_A)-[:REL_1]->(:LABEL_B)<-[:REL_2]-(output:Label_C)

My attempt:

MATCH (common:Label_A)-[:REL_1]->(:LABEL_B)<-[:REL_2]-(output:Label_C)
WITH DISTINCT common, output, count(id(common)) AS cnt WHERE cnt >= [THRESHOLD]
RETURN DISTINCT output

Look at the appended image for an example. The threshold is set to be 3. enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Using size, you can build your query like this:

MATCH (common:Label_A) WHERE size((common)--(:Label_B)--(:Label_C)) > 3
WITH common
MATCH (common)--(:Label_B)--(output:Label_C)
RETURN DISTINCT output

where 3 can be replaced with your actual threshold.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...