Finding other people who bought the same products

I want to take a name, find a list of products that person bought, find a list of people who bought the same product, and then return a list of other products those people bought, so long as the original customer didn't also buy them.

Here's the query I wanted to do that:

MATCH (c: customer {customer_name: "SOME GUY"})
MATCH (c)-[:madePurchase]->(:transaction)-[:onShelf]->(:shelf)-[:hasName]->(p:product)
MATCH (other:customer {division: c.division})-[:madePurchase]->(:transaction)-[:onShelf]->(:shelf)-[:hasName]->(p:product)
MATCH (other)-[:madePurchase]->(:transaction)-[:onShelf]->(:shelf)-[:hasName]->(rec:product)
WHERE NOT exists ( (c)-[:madePurchase]->(:transaction)-[:onShelf]->(:shelf)-[:hasName]->(rec) )

RETURN rec.common_name, rec.product_name, COUNT(*) AS score ORDER BY score DESC

This query is taken almost directly from a tutorial on this subject.

It's not working for me, and when I began testing out hypotheses something weird happened.

Here's what I get when I try to return all the purchases made by SOME GUY:

When I try to return all the other customers who bought the same products as SOME GUY, I get back the exact same graph:

Note that the two RETURN statements are asking for entirely different customers.

I've been at this for hours, what could possibly be going wrong?

Please post the link from where you copied the queries. Thanks

1 Like

Here's a good shot: How to Design Retail Recommendation Engines with Neo4j - YouTube