Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-02-2019 09:31 AM
Hello guys, I need help to create a neo4j query.
I have a database containing information of coupons and their respective products bought by customers.I am trying to make a query for, given a certain product, find the coupons that contain this item, and then return the items that appear with the highest frequency in these coupons, in order to recommend them to a customer.
The model of my graph is as follows:
(:Coupon {couponID: id})-[:CONTAINS {amount: numberProducts}]->(:Product {productID: id, productName: Name}
I created the following query:
MATCH (:Product {productID:'49138'})<-[:CONTAINS]-(coupon:Coupon)
WITH coupon as coupon
MATCH (coupon)-[:CONTAINS]->(products:Product) WHERE products.productID <> '49138'
RETURN products.productName, count(products.productID) AS nProdsRec ORDER BY nProdsRec DESC LIMIT 10
I think this query is able to return the items that appear with higher frequency in the coupons that have the product being bought by the customer i want to recommend new items. The problem is that I am not using the amount of products bought (property of the relationship CONTAINS) to enhance my query. Could someone help me to combine that with my current query?
04-02-2019 09:42 AM
You can give an alias to the Pattern of your relationship like:
MATCH (:Product {productID:'49138'})<-[:CONTAINS]-(coupon:Coupon)
WITH coupon as coupon
MATCH (coupon)-[relprop:CONTAINS]->(products:Product)
WHERE products.productID <> '49138'
RETURN products.productName, count(products.productID) AS nProdsRec, sum(relprop.amount) as sumProds ORDER BY nProdsRec DESC LIMIT 10
04-02-2019 09:50 AM
Thank you for your help Benjamin.
All the sessions of the conference are now available online