SET 与密码中的 CASE 语句结合使用 [英] SET in combination with CASE statement in cypher

查看:25
本文介绍了SET 与密码中的 CASE 语句结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将两个不同的关系属性设置为一个计数,并根据另一个关系属性的值使用 case 构造.http://console.neo4j.org/?id=rt1ld5

I am tryin to set two different relationship properties to a count, with a case construct depending on the value of another relationship property. There is a console at http://console.neo4j.org/?id=rt1ld5

cnt 列包含 r.value 出现的次数.控制台中初始查询的前两行表示术语Car"链接到 1 个被认为相关的文档,以及两个被认为不相关的文档.

the cnt column contains the number of times r.value occurs. The two first rows of the initial query in the console indicate that the term "Car" is linked to 1 document that is considered relevant, and to two documents that are considered not relevant.

我想在具有两个属性的 (user) 和 (term) 之间的 [:INTEREST] 关系上设置一个属性,指示兴趣链接到被认为相关或不相关的文档的次数.所以对于 (John)-[r:INTEREST]->(Car) 我想要 r.poscnt=1 和 r.negcnt=2

I want to SET a property on the [:INTEREST] relation between (user) and (term) with two properties, indicating how many times an interest is linked to a document that is considered relevant or not. So for (John)-[r:INTEREST]->(Car) I want r.poscnt=1 and r.negcnt=2

我正在为 CASE 结构苦苦挣扎.我尝试了各种方法,这是我得到的最接近的方法.

I.m struggling with the CASE construct. I tried various ways, this was the closest I got.

MATCH (u:user)-[int:INTEREST]->(t:term)<-[:ISABOUT]-(d:doc)<-    [r:RELEVANCE]-(u)
WITH int, t.name, r.value, count(*) AS cnt
CASE
  WHEN r.value=1 THEN SET int.poscnt=cnt
  WHEN r.value=-1 THEN SET int.negcnt=cnt
END

但它返回一个错误

Error: Invalid input 'A': expected 'r/R' (line 3, column 2)
"CASE"
  ^

推荐答案

做到了!另请参阅 http://console.neo4j.org/?id=rq2i7j 上的控制台>

This did it! Also see console at http://console.neo4j.org/?id=rq2i7j

MATCH (u:user)-[int:INTEREST]->(t:term)<-[:ISABOUT]-(d:doc)<-[r:RELEVANCE]-(u)
WITH int, t, 
     SUM(CASE WHEN r.value= 1 THEN 1 ELSE 0 END ) AS poscnt, 
     SUM(CASE WHEN r.value= -1 THEN 1 ELSE 0 END ) AS negcnt
SET int.pos=poscnt,int.neg=negcnt
RETURN t.name,int.pos,int.neg

这篇关于SET 与密码中的 CASE 语句结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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