cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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?

2 REPLIES 2

ameyasoft
Graph Maven

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

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online