I am trying to build recommended products per customer. I have a query that gets my recommended products BUT when executed in apoc.periodic.iterate I get multiple relationships. (I get the number of relationships in my LIMIT). I works when I LIMIT 1 and BATCH 1
CALL apoc.periodic.iterate("MATCH (c:customer)-[]->(p:product) WHERE EXISTS (c.age) AND NOT (c)<-[:RECOMMEND]-() RETURN c LIMIT 2","MATCH (c)-[]->(p:product)<-[]-(nc:customer)
WITH COLLECT (DISTINCT p) as prods, c, p, nc
WHERE c <> nc AND ALL(p in prods WHERE (p)<-[]-(nc)) AND nc.age > (c.age - 10) AND nc.age < (c.age + 10)
MATCH (nc)-[]->(np)-[]->(u:use)
WITH np, u, c, COLLECT(p.article_id) as arts
WHERE not np.article_id in arts
WITH c, u.name as use, np.article_id as product, count(*) as score
ORDER BY score DESC
WITH c, use, Collect(product)[0..1] as products
WITH c, COLLECT(products)[0..12] as recomendation
UNWIND recomendation AS x
UNWIND x AS rec
MATCH (r:product{article_id: rec})
WITH c, r
CREATE (r)-[:RECOMMEND]->(c)",
{batchSize:2, parallel: true, iterateList:true})
LIMIT | BATCH | PARALLEL | ITERATELIST | DURATION |
---|---|---|---|---|
1 | 1 | True | true | 5985 ms |
1 | 1 | true | false | 35822 ms. |
1 | 1 | False | false | 4864 ms. |
1 | 1 | False | true | 492 ms. |
2 | 1 | True | true | 2286 ms. |
*double edges | ||||
2 | 1 | true | false | 6227 ms |
*double edges | ||||
2 | 1 | False | false | 61752 ms. |
double edges | ||||
2 | 1 | False | true | 403 ms. |
double edges |