Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-10-2020 02:01 AM
I have a doubt in query 4 of this article here Can someone please explain what line no. 6 and 7 are doing.
MATCH (c:Customer)-[:PURCHASED]->(o:Order)-[:PRODUCT]->(p:Product)
WITH c, count(p) AS total
MATCH (c)-[:PURCHASED]->(o:Order)-[:PRODUCT]->(p:Product)
WITH c, total,p, count(o)*1.0 AS orders
MERGE (c)-[rated:RATED]->(p)
ON CREATE SET rated.rating = orders/total
ON MATCH SET rated.rating = orders/total
WITH c.companyName AS company, p.productName AS product, orders, total, rated.rating AS rating
ORDER BY rating DESC
RETURN company, product, orders, total, rating LIMIT 10
05-10-2020 05:08 PM
Here's the documentation for ON CREATE and ON MATCH, which are clauses you can only use directly following a MERGE clause.
MERGE is like a MATCH of a pattern, and then if the pattern doesn't exist, it will perform a CREATE, so this allows some conditional behavior on setting properties depending upon the result of the MERGE.
In this particular case, the same operation is being performed no matter if the MERGE only needed to MATCH to an existing pattern, or CREATE it. So ideally you wouldn't use either of these, you would just use SET
after the MERGE.
Only when the behavior needs to differ between one case and the other would you want to use these in your query.
All the sessions of the conference are now available online