neo4j - Cypher:嵌套 FOREACH 中的匹配节点
问题描述
我有一个嵌套的 FOREACH 循环,需要将标签与多个标签匹配。
OPTIONAL MATCH (a: Article {URL: event.URL})
FOREACH(ignoreme in case when a is null then [1] else [] end |
CREATE (a: Article {URL: event.URL})
//other statements ..... //
FOREACH (relation in CASE WHEN event.article.nlp_relations is not null then event.article.nlp_relations else [] end |
match (a)-[:HAS_NLP_TAG]->(t_from) where (t_from:Tag or t_from:Entity) and t_from.value = relation.from.value
match (a)-[:HAS_NLP_TAG]->(t_to) where (t_to:Tag or t_to:Entity) and t_to.value = relation.to.value
call apoc.create.relationship(t_from,relation.type , {}, t_to)
)
)
这不起作用,因为您不能在 foreach 中使用匹配项。我可以说总会有一个节点要匹配,因为它会在同一个查询的前面创建。所以它永远不会为空,但我不知道如何以目前的形式表达这一点。谁能帮忙
解决方案
看起来您可以将您的第二个重新制定FOREACH
为正常的MATCH
组合CREATE
,例如(我没有尝试运行它):
OPTIONAL MATCH (a: Article {URL: event.URL})
FOREACH(ignoreme in case when a is null then [1] else [] end |
CREATE (a: Article {URL: event.URL}
)
//other statements ..... //
unwind Case When event.article.nlp_relations is null then [] else event.article.nlp_relations end as relation
match (a)-[:HAS_NLP_TAG]->(t_from) where (t_from:Tag or t_from:Entity) and t_from.value = relation.from.value
match (a)-[:HAS_NLP_TAG]->(t_to) where (t_to:Tag or t_to:Entity) and t_to.value = relation.to.value
call apoc.create.relationship(t_from,relation.type , {}, t_to)
)
WITH
您可能仍需要在 -语句之前插入适当的 -MATCH
语句。
推荐阅读
- java - 为什么选择 Reactor Mono
被识别为空单声道? - php - ftp_login 在第二次登录尝试时失败?
- mysql - 由于发生redis错误,用户无法登录laravel网站。重新启动redis服务时,不会出现此错误
- vb.net - 是否有跳过 for 循环中步骤的功能?
- c# - Process.Threads 不包含进程产生的线程的完整列表
- mstest - specflow.exe 生成 html 报告的替代方法是什么
- android - 如何将所选项目保存在日历中
- php - 在 Laravel 中限制用户单次和多次登录
- c# - 创建一个 CompactSql 数据库并将其连接字符串动态添加到实体框架
- php - 拉拉维尔;根据另一个表中的值播种到不同的表