节点重用,而不是创建新节点?

时间:2019-04-14 22:42:27

标签: cypher graph-databases redisgraph

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

  • 该动作存在,请使用它,而不是创建一个新动作
  • 状态存在,使用它,而不是创建新状态

并在单个查询中完成。

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

cars = 3;
friendsCars = 4;
let mostCars = ?; 
//needs to be the value of the 
//greater of the two variables

if (friendsCars > cars || cars > friendsCars)
     //checking which 
     //is true
     {
        console.log( mostCars);
     }  
//assign the value of the true statement to mostCars.

我使用辐射图。


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

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

1 个答案:

答案 0 :(得分:2)

目前,RedisGraph不支持混合使用MATCH和MERGE子句,因此除了像您一样拆分查询之外,您没有太多选择, 一种建议是将这三个查询包装在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混合使用后,我们将更新j/build