Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-03-2020 02:46 AM
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???
03-03-2020 03:27 AM
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)
03-06-2020 01:37 AM
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.
03-06-2020 01:41 AM
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})
03-06-2020 01:43 AM
ok thanks for that but I can also get another parameter, not just ram, but also {cpu, bandwidth} etc??
03-06-2020 02:17 AM
so you can have multiple
:param ram=>'ram_value';
:param cpu->'cpu_value'
etc.
Match (p:Product{ram:$ram, cpu:$cpu})
03-06-2020 02:20 AM
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??)
03-06-2020 03:15 AM
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.
All the sessions of the conference are now available online