neo4j中的除法计算不正确

时间:2017-05-31 05:46:10

标签: neo4j cypher

在查询之间的neo4j

 <td #x ng-mouseover="x.isHover=true" ng-mouseleave="x.isHover=false">{{user.Name}}
  <example-popover *ngIf="x.isHover"></example-popover>
</td>

MATCH (a), (b)
WHERE a<>b
WITH length(shortestPath((a)-[]->(b))) AS dist, a, b
RETURN DISTINCT sum(1.0/dist) AS closeness, a 
ORDER BY closeness DESC

没有区别。那是MATCH (a), (b) WHERE a<>b WITH length(shortestPath((a)-[]->(b))) AS dist, a, b RETURN DISTINCT sum(dist) AS closeness, a ORDER BY closeness DESC 无效。

图表

1.0/dist

两个查询都会返回一个答案:

CREATE (A {name: "A"})
CREATE (B {name: "B"})
CREATE (C {name: "C"})
CREATE (D {name: "D"})
CREATE (E {name: "E"})

CREATE (A)-[:TO]->(E)
CREATE (A)-[:TO]->(B)
CREATE (B)-[:TO]->(C)
CREATE (B)-[:TO]->(E)
CREATE (C)-[:TO]->(D)
CREATE (E)-[:TO]->(D)
CREATE (D)-[:TO]->(B)

我想弄明白为什么。

1 个答案:

答案 0 :(得分:0)

如果您尝试仅打印dist值:

MATCH (a), (b)
WHERE a<>b
WITH length(shortestPath((a)-[]->(b))) AS dist, a, b
RETURN dist

返回:

dist
1
null
null
1
null
1
null
1
null
null
1
null
null
1
null
null
null
null
null
1

因此,dist1.0/dist之间没有区别。运营商/有效,只需尝试返回2.0/dist,您就会看到预期结果。希望有所帮助。