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

查看:165
本文介绍了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出现的次数.控制台中初始查询的前两行表明,汽车"一词链接到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.

我想在(用户)和(词)之间的[: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天全站免登陆