我需要一个密码查询来提取标有VIEWED和UPDATED的关系,并显示每个用户边缘权重的总和。
我想根据他查看或更新任何文档的次数为每个用户计算一个值。
实施例: 用户查看文档d 3次,文档e 4次。同一用户更新文档f 6次。 我想在每次用户更新或查看文档时分配点数,因此我需要如下结果:user:a - views:7 - updates:6
这就是我目前所拥有的:
javax.faces.ViewState
答案 0 :(得分:2)
你几乎得到了,很好的尝试!
要么像这样:
MATCH (n:User)-[r:VIEWED|UPDATED]->(f:File)
WHERE f.id IN ['some_id','another_id']
RETURN n, type(r) as type, sum(r.weight) as weight
或者如果您想要每个用户一行:
MATCH (n:User)-[r:VIEWED|UPDATED]->(f:File)
WHERE f.id IN ['some_id','another_id']
WITH n, type(r) as type, sum(r.weight) as weight
RETURN n, collect({type:type,weight:weight})
答案 1 :(得分:0)
此查询适用于我:
MATCH (n:User)-[r1:VIEWED]->(f:File)
OPTIONAL MATCH (n:User)-[r2:UPDATED]->(f:File)
WHERE f.id IN ['some_id', 'another_id']
return n, sum(r1.weight) as totalViewedWeight, sum(r2.weight) as totalUpdatedWeight
ORDER BY totalUpdatedWeight DESC, totalViewedWeight DESC;