节点重用,而不是创建新节点? [英] Node reuse, instead of creating new ones?

查看:87
本文介绍了节点重用,而不是创建新节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以以下方式创建(动作)->(状态)对,以便于:

I'm trying to create (action)->(state) pair in such a way so that if :


  • 该动作存在,使用它,而不是创建新的

  • 状态存在,使用它,而不是创建新的

并在单个查询中完成。

如果状态与以前的调用不同,我将创建一个新的动作节点。因此,我最终得到了多个相同的动作节点。

The one I have creates new action node if the state is different, from previous calls. So I end up with multiple action nodes which are the same.

    query =  "merge (:state {id:%s})-[:q {q:%s}]->(:action {id:%s})" % (state, 0, action)

我使用半径图。

唯一的方法是使用3个查询而不是1个查询来实现此目的:

The only way is to use 3 queries instead of 1 to achieve this :

graph.query mem 'merge (:state {id:9})'
graph.query mem 'merge (:action {id:9})'
graph.query mem 'match (s:state), (a:action) where s.id = 9 and a.id = 9 create (s)-[:q {q:0.3}]->(a)' 


推荐答案

目前RedisGraph不支持混合使用MATCH和MERGE子句,因此除了像您一样拆分查询外,您没有太多选择,
一个建议将这三个查询包装在MULTI EXEC中:

At the moment RedisGraph doesn't supports mixing the MATCH and MERGE clauses, and so you don't have much options besides splitting the query as you did, one suggestion would be to wrap those three queries within a MULTI EXEC:

MULTI
graph.query mem 'merge (:state {id:9})'
graph.query mem 'merge (:action {id:9})'
graph.query mem 'match (s:state), (a:action) where s.id = 9 and a.id = 9 create (s)-[:q {q:0.3}]->(a)'
EXEC

这应该加快速度,
我们将更新此处一旦MATCH和MERGE可以混合使用。

This should speed things up, we'll update here once MATCH and MERGE can be mixed.

这篇关于节点重用,而不是创建新节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆