cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

building recommendation system using weight as relation

hello.

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 scoreScreenshot (83).png
1 ACCEPTED SOLUTION

Something like the following: 

match (user:Users{m_id:""})
match (m:Products{m_id:""})-[:HAS]->(a:Specifications)
merge (user) -[f:FAVORITE]-> (m)
on create set f.score = 0
on match set f.score = f.score + 10
merge (user)-[w:WEIGHT]->(a)
on create set w.score = 0
on match set w.score = w.score + 20

View solution in original post

6 REPLIES 6

You can use ‘on create’ clause with each merge to initialize each weight and use ‘on match’ to update each weight. 

hi again and tnx for helping.

do you mean something like this ?

match (user:Users{m_id:}),(m:Products{m_id:"})-[:HAS]->(a:Specifications)
MERGE (user) -[:FAVORITE]-> (m)
on create MERGE (user)-[:WEIGHT{score:10}]->(a)
i think after on create we should use SET
and one more question 
how should i check that if i already created that relation , update weight

Something like the following: 

match (user:Users{m_id:""})
match (m:Products{m_id:""})-[:HAS]->(a:Specifications)
merge (user) -[f:FAVORITE]-> (m)
on create set f.score = 0
on match set f.score = f.score + 10
merge (user)-[w:WEIGHT]->(a)
on create set w.score = 0
on match set w.score = w.score + 20

really help full tnx sir really appreciate

hello again i have one more problem😅

im adding a property for specifications that name of them is "color" "type" "size" and its called "ratio" the reason is i want to give them some coefficient to give recommend most based on types then colors and so on

so now i wanna get that ratio and multiply with weight that has relation with that sub specification

this is what i write for give recommend but couldnt save ratio in other variable and then multiply with weight 

 
match (u:Users{m_id:"62aad7f641f29f97fbdead54"})-[w:WEIGHT]->(a:Specifications)
match (u)-[w]->(a)<-[:HAS]-(prod:Products)
match (a)-[:is]->(b:Specifications)
where  b.name = "color" and w<i dont know how to select that relation> set sc = b.ratio* w
with u , prod ,collect(w.score)as scorelist, sum(w.score) as score ,sc
return u.name as user,prod.name as products ,scorelist, sc as test,score order by score desc
 
 

and one more thing how to update weight with that specific attribute 

is it even possible to have some weight relation and 1 property that the property has different value ?

and if its not possible what do you think we can do

tnx for your time