O'Reilly logo

Learning Neo4j 3.x - Second Edition by Rik Van Bruggen, Jérôme Baton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Recommendations based on brand loyalty

Obviously, we all understand that if we already own a product of a particular brand, it is likely that we will be more interested in other products that are manufactured by that same brand. So let's find the people that already have more than one product of a certain brand and see if we can recommend other products by that brand. Here's the query example:

MATCH (p:Person)-[b:BOUGHT]->(prod1:Product)-[:MADE_BY]->(br:Brand)<-[MADE_BY]-(prod2:Product) 
WITH p, br, prod2, count(prod1) as NrOfBrandProducts 
WHERE not(p-[:BOUGHT]->prod2) and NrOfBrandProducts > 1 
RETURN p.name as Person, br.name as Brand, collect(prod2.name) as RecommendedProducts 
ORDER BY Person ASC; 

The pattern should be fairly similar, but ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required