combining foreach and case to set/remove relation properties

为君一笑 提交于 2019-12-11 06:29:22

问题


I have two collections, one containing nodes, and another containing rels and nodes (see http://console.neo4j.org/?id=ijoqaa)

What I try to achieve is to update the rel properties , depending on the whether a node in one collection is also present in the other. The code below illustrates this (hopefully), although it's not valid cypher.

FOREACH (iterm in iterms|
    CASE
        WHEN NOT (iterm[1] IN iaterms) THEN
            REMOVE iterms[0].pos,iterms[0].neg
            SET iterm[0].explicit=1
    END
)

Question: what is the way to do this in cypher ?


回答1:


Does this work?

MATCH (u:user)-[i:INTEREST]->(t)
WHERE NOT u-[:RELEVANCE]->()-[:ISABOUT]->t
REMOVE i.neg, i.pos
SET i.explicit = 1



回答2:


Looking at what you have at the console, I think your query could be quite simple. There's no need to iterate with a foreach construction.

MATCH (u:user)-[r:RELEVANCE]->()-[ia:ISABOUT]->(t:term)
WITH u, collect(t) AS terms
MATCH (u)-[i:INTEREST]->(t2:term)
WHERE NONE(t IN terms WHERE t = t2)
REMOVE i.pos, i.neg
SET i.explicit = 1


来源:https://stackoverflow.com/questions/22482138/combining-foreach-and-case-to-set-remove-relation-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!