我怎样才能避免在 neo4j 中多次访问具有相同 属性 的节点?

how can i avoid visiting a node with same property more than once in neo4j?

我的 Cypher 查询:

MATCH p =(o:Order)-[r:seeks*2..8]->(o:Order)
WHERE o.Name="000093" AND ALL(x IN tail(nodes(p)) WHERE SINGLE(y IN    tail(nodes(p)) WHERE x=y))
RETURN extract(n IN nodes(p)| n.Name) AS OrderID, extract(u IN nodes(p)| u.UserName) AS UserName,length(p), endNode(r[0])
ORDER BY length(p)

我想避免在路径中有具有相同 属性 值的节点,如何避免它们?

["000093","000090","000096","000097","000107","000091","000089","000093"]
["yunis","gio","Anhar","Jhon","**shakilbit**","xalima","**shakilbit**","yunis"]

所以,订单 0000107 和 000089 是由同一个用户名 shakilbit 下达的,有什么办法可以避免在同一路径下使用这些订单,谢谢! NEO4J..据我所知,社区非常有帮助。

使用 APOC Procedures,您可能希望将您的集合作为一个集合(消除重复值)并比较大小。如果存在重复项,集合的大小将更小。

MATCH p =(o:Order)-[r:seeks*2..8]->(o:Order)
WHERE o.Name="000093" AND ALL(x IN tail(nodes(p)) WHERE SINGLE(y IN    tail(nodes(p)) WHERE x=y))
WITH p, o, r, extract(u IN nodes(p)| u.UserName) AS UserName
// need to make some adjustments since first and last nodes are same
WHERE size(UserName) - 1 = size(apoc.coll.toSet(tail(UserName)))
RETURN extract(n IN nodes(p)| n.Name) AS OrderID, UserName, length(p), endNode(r[0])
ORDER BY length(p)

替代方法是在 UserName 集合上重复 ALL(x in tail...) WHERE single()... 谓词(或者在现有的 ALL() 谓词中包括此检查,尽管这可能很昂贵)。您可能想对每个进行 PROFILE,看看哪个性能更好。