Question

I'm learning cypher with Neo4j but I'm having some problems that show I still don't quite get it.

I'm trying to write a query that finds a subgraph and then excludes nodes from that subgraph that are connected to a specified node.

In practice, it's a recommendation problem: I find a set of recommendations, but want to exclude those things that a target use already knows about.

I thought I could do something like:

match (u:User{id:"some id"}), (:Category{title:"some category"})-[:categorizes]->(i:Item) 
where not (u)-[:knows_about]-(i) 
return  i

but this doesn't work.

Can anyone explain what I'm doing wrong/what I should be doing?

Was it helpful?

Solution

I think you want the following:

MATCH (:Category{title:"some category"})-[:categorizes]->(i:Item)
MATCH (u:User {id:some_id})
WHERE  not (u)-[:knows_about]-(i) 
RETURN i

You might want to add a direction in the second WHERE clause (performance!).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top