Hello everyone, I wanted to ask about the following question. I have a node that is called Product. This node has lots of properties eg., name, ram, CPU, price etc.... What I want to do is to take a query as eg,. 32GB of ram, and to query over sets (key:value). I want to get all the products that contain 32GB of ram in their key:value pairs. Is there something I can do for that???
Below will give you all the Products with having node having ram as 32GB
Match(n:Product{ram:'32GB'}) Return n
Please let me know what you mean by sets(key:value)
When I mean sets, the idea is that I would like to take the phrase and to see if it matches to with the key and the value from the database. so [32GB ram] to match with (p:Product{ram:'32GB'}), but this to be done dynamically because I take this phrase from the user and it can be everything.
So in short you need to pass value in the match query as parameter?
Set the parameter as ram
:param ram=>'value'
Now hit your query
(p:Product{ram:$ram})
ok thanks for that but I can also get another parameter, not just ram, but also {cpu, bandwidth} etc??
so you can have multiple
:param ram=>'ram_value';
:param cpu->'cpu_value'
etc.
Match (p:Product{ram:$ram, cpu:$cpu})
The point is that I have 100 attributes like ram and cpu and I dont know which one the user will look for. Is there any other option to not define it from the beginning and just to match randomly (eg., query over the keys and values and if the match with the phrase then to return the results??)
Any ways you need to pass the parameter, irrespective it is null though. In the below code I am saying if the passed value is null then consider all the records for that property else consider the value passed .
:param ram=>null
:param cpu=>'cpu_value'
**Match (p:Product)
Where (Case COALESCE($ram,'DefaultVal') When 'DefaultVal' Then p.ram=~'.' Else p.ram=$ram)
And (Case COALESCE($cpu,'DefaultVal') When 'DefaultVal' Then p.cpu=~'.' Else p.cpu=$cpu)
Return p **
You can manipulate the above code as per your convenience.