我在neo4j上有以下数据集
create (recipe1:recipe {name: 'recipe-1'})
create (recipe2:recipe {name: 'recipe-2'})
create (recipe3:recipe {name: 'recipe-3'})
create (recipe4:recipe {name: 'recipe-4'})
create (recipe5:recipe {name: 'recipe-5'})
create (recipe6:recipe {name: 'recipe-6'})
create (user1:user {name: 'user-1'})
create (user2:user {name: 'user-2'})
create (user3:user {name: 'user-3'})
create (user4:user {name: 'user-4'})
create
(user1)-[:LIKES]->(recipe1),
(user1)-[:LIKES]->(recipe2),
(user1)-[:LIKES]->(recipe4),
(user2)-[:LIKES]->(recipe4),
(user2)-[:LIKES]->(recipe6),
(user3)-[:LIKES]->(recipe1),
(user3)-[:LIKES]->(recipe3),
(user3)-[:LIKES]->(recipe6),
(user4)-[:LIKES]->(recipe4)
并尝试运行以下查询:
match (user4:user {name: 'user-4'})-[LIKES]->recipe<-[:LIKES]-slm-[:LIKES]->recommendations
where not(user4 = slm) and not(user4-recommendations)
return count(*) AS recommendationsWeight,
recommendations.name AS name
order by recommendationsWeight DESC, name DESC
但我收到以下错误:
Type mismatch: expected Float or Integer but was Node (line 2, column 32 (offset: 123))
"where not(user4 = slm) and not(user4-recommendations)"
^
任何想法我在这里做错了什么?
更新
我想在not(user4-recommendations)
这里做的是说任何与user4无关的建议。例如,考虑一下:
match (user4:user {name: 'user-4'}), (recipe1:recipe {name: 'recipe-1'})
create (user4)-[:DISLIKES]->(recipe1)
因此,我的推荐查询结果不应包含recipe1
,因为用户之前已与之互动过。
答案 0 :(得分:2)
你有一个拼写错误:: -
而不是=
。不要忘记括号:
match (user4:user {name: 'user-4'})-[LIKES]->
(recipe)
<-[:LIKES]-(slm)-[:LIKES]->
(recommendations)
where not(user4 = slm) and not(user4 = recommendations)
return count(*) AS recommendationsWeight,
recommendations.name AS name
order by recommendationsWeight DESC,
name DESC
我认为您正在尝试建立一个推荐系统。然后,请求将更容易(不需要检查,它可以工作,因为它没有使用zero-length path):
match (user4:user {name: 'user-4'})
-[:LIKES]->(recipe)<-[:LIKES]-
(slm)-[:LIKES]->(recommendations)
where not ( (user4)-[:DISLIKES|LIKES]->(recommendations) )
return recommendations,
count(recommendations) as recommendationsWeight
order by recommendationsWeight desc,
recommendations.name asc