Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-07-2022 07:09 PM
in my neo4j database, there are many kinds of relationships between people and vehicles, and each relationship has a weight value:
Relationship attributes include frequency and weight. For example, the relationship between person A and vehicle B is as follows
In my query statement, I need to find the relationship and nodes whose weight * times is greater than 3. this is my Cypher :
match p = (u:user)-[r]->(v:vehicles) where r.frequency * r.weight > 3 return p
but I will dynamically adjust the weight of the relationship according to the query results. When the data volume is very large, this process is very slow.
Is there a way to define a relational weight as a variable or some other way to quickly change the weight value?
Looking forward to your help!
03-07-2022 11:43 PM
One suggestion I would make is to store the product of weight and frequency as another relationship property, so you don’t have to compute it each time you query. You could index the new property as well.
03-07-2022 11:57 PM
In my model, the weight of the relationship will be dynamically adjusted according to the calculation results. There are so many relationships that it will be very slow for me to update the weight of the relationship with the following statement:
Match (u:user)-[r:Driving]->(v:vehicles) set r.eight = 0.5
But before the model is stable, I have to modify the weight value repeatedly according to the result of calculation. Is there any good way?
03-08-2022 02:53 PM
I was just suggesting that if you saved the product of the frequency and weight for each relationships, your query may run faster. Adding an index to the new property may help further. So every time you update the weight during your algorithm, you also set an additional attribute to the product. This will avoid the query from having to compute this same result each time.
current:
match p = (u:user)-[r]->(v:vehicles) where r.frequency * r.weight > 3 return p
new query:
match p = (u:user)-[r]->(v:vehicles) where r.freq_weight_product > 3 return p
I don't know of another way to set a property outside of SET.
If you are running an iterative algorithm that accesses the data via a driver, maybe consider implementing it in your own procedure that runs on the server if performance is an issue.
You could also try implementing it with one of the apoc.periodic methods, if it is not too complex.
03-08-2022 07:01 PM
Although we haven't found the method of dynamic setting, thank you very much for your suggestion
All the sessions of the conference are now available online