Optimizing for recommendations: best practices in graph modeling
We have a graph now, with data loaded the way we want to consume it and representing the context of the data. Still, the graph represents only the original context provided. Say we want to consume the data by season and year – we still need to build queries to retrieve it. Since Neo4j is schema optional, maybe we can do some post-processing and add extra relationships to consume the data in that way.
In this Cypher script, we are creating seasonal relationships:
- For each customer, iterate through the transactions and assign a season value based on month and year:
MATCH (c:Customer) WITH c CALL { WITH c MATCH (c)-[:START_TRANSACTION]->(s) MATCH (c)-[:LATEST]->(e) WITH c,s,e MATCH p=(s)-[:NEXT*]->(e) WITH c, nodes(p) as nodes ...