迭代Neo4j关系并返回关系属性的最小值

时间:2014-10-09 09:48:56

标签: neo4j cypher

我想迭代“开始节点”和“结束节点”之间的关系。 确实,有我的密码请求:

 MATCH (ar1:Article)-[:PART_OF]->()-[:SERIES]->(s1),
(ar2:Article)-[:PART_OF]->()-[:SERIES]->(s2),
(ar1)-[:CREATOR]->(au1:Author),
(ar2)-[:CREATOR]->(au1:Author),

p1 = (au1)-[CONTRIBUTOR*]->(au2:Author) 

WITH REDUCE (edge IN relationships(p1)|weight + 1/edge.fdegree) AS 
strength_au1_au2_p1,ar1 AS ar1,s1 AS s1,ar2 AS ar2,s2 AS s2,au1 AS au1,au2 AS au2

WHERE s1.name='WWW' AND s2.name='Pods' AND ar2.year  >2010.0 AND ar1.year  >2010.0 
AND strength_au1_au2_p1<5.0

RETURN ar1,s1,ar2,s2,au1,au2,ar1.year AS calc_fuzzy_ar1_year_recent,ar2.year AS
calc_fuzzy_ar2_year_recent,strength_au1_au2_p1 AS calc_fuzzy_length_p1_short**

现在我想迭代 CONTRIBUTOR * 关系(在p1中)并获取每个'fdegree'并返回p1中关系的最小值(fdegree)

谢谢大家

1 个答案:

答案 0 :(得分:0)

试试这个:

MATCH (au1:Author)<-[:CREATOR]-(ar1:Article)-[:PART_OF]->()-[:SERIES]->(s1),
      (au2:Author)<-[:CREATOR]-(ar2:Article)-[:PART_OF]->()-[:SERIES]->(s2)
WHERE s1.name='WWW' AND s2.name='Pods' AND ar2.year  >2010.0 AND ar1.year  >2010.0 
WITH au1,au2,ar1,ar2,s1,s2
MATCH (au1)-[rels:CONTRIBUTOR*]->(au2:Author) 
WHERE REDUCE (weight = 0, edge IN rels | weight + 1/edge.fdegree) < 5.0
RETURN au1,au2,ar1,ar2,s1,s2,
      REDUCE (weight = 1000000, edge IN rels | 
              case when weight < edge.fdegree then weight else edge.fdegree end) as min_degree