Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...