0

in my graph we have users that have 2 relation called "favorite" and "seen" with products and product have relation called has with some specification as colors(red blue...) , types(jeans....) and sizes (30...)

so i make some query that when i wanna create favorite or seen relation , it makes a relation with that specific user and the specification of that product calling "weight" and set property for that called "score" and i wanna increase this score every time user that set product to favorite or just seeing that product for example when a user see the product score change to +10 and for favorite change to +20 and then we recommend products with specifications that have most score

my query is

match (user:Users{m_id:""}),(m:Products{m_id:""})-[:HAS]->(a:Specifications)
MERGE (user) -[:FAVORITE]-> (m)
merge (user)-[:WEIGHT{score:0}]->(a)

and one more problem with this query is i dont wanna make new relation if i already have it i just wanna increase the scoreenter image description here

1 Answers1

0

You would only merge on the relationship and then set the property accordingly.

MERGE (user)-[w:WEIGHT]-(a)
ON CREATE SET w.score = 10
ON MATCH SET w.score = w.score+10

Or alternatively update it unconditionally

MERGE (user)-[w:WEIGHT]-(a)
SET w.score = coalesce(w.score,0)+10
Michael Hunger
  • 41,339
  • 3
  • 57
  • 80