Reputation: 58454
I have the below data set on 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)
and trying to run the below query:
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
but I am getting the below error:
Type mismatch: expected Float or Integer but was Node (line 2, column 32 (offset: 123))
"where not(user4 = slm) and not(user4-recommendations)"
^
any idea what I am doing wrong here?
Update:
What I want to do here with not(user4-recommendations)
is to say that any recommendations which user4 has no relationship with. For example, consider this:
match (user4:user {name: 'user-4'}), (recipe1:recipe {name: 'recipe-1'})
create (user4)-[:DISLIKES]->(recipe1)
So, the result of my recommendation query should not include recipe1
as user has interacted with it before.
Upvotes: 0
Views: 2317
Reputation: 29172
You have a typo:: -
instead =
. And do not forget the parentheses:
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
I think that you're trying to build a recommendatory system. Then, the request will be easier (no checks are not necessary, it works because it is not used a 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
Upvotes: 2