cypher distinct使用with参数返回重复

时间:2018-03-22 17:10:21

标签: neo4j cypher cypher-3.1

MATCH (c:someNode)   WHERE  LOWER(c.erpId) contains (LOWER("1")) 
OR  LOWER(c.constructionYear) contains (LOWER("1")) 
OR  LOWER(c.label) contains (LOWER("1"))
OR  LOWER(c.name) contains (LOWER("1")) 
OR  LOWER(c.description) contains (LOWER("1"))with collect(distinct c) as rows, count(c) as total 
    MATCH (c:someNode)-[adtype:OFFICIAL_someNode_ADDRESS]->(ad:anotherObject) 

WHERE toString(ad.streetAddress) contains "1"     
OR toString(ad.postalCity) contains "1" 
with distinct rows+collect( c) as rows, count(c) +total as total
 UNWIND rows AS part

RETURN part order by part.name SKIP 20 Limit 20

当我运行以下cypher查询时,它会返回重复的结果。跳过它似乎也不起作用。我在做什么?

1 个答案:

答案 0 :(得分:1)

当您使用WITH DISTINCT a, b, c(或RETURN DISTINCT a, b, c)时,这意味着您希望每个结果记录({a: ..., b: ..., c: ...})都是不同的 - 它不会以任何方式影响内容任何可能属于abc的列表。

以下是可能适合您的简化查询。它根本不使用LOWER()TOSTRING()函数,因为它们似乎是多余的。它也只使用一个MATCH/WHERE对来查找所有感兴趣的节点。如果WHERE个节点有true个{{1}利益。请注意,不需要anotherObject

DISTINCT