Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-06-2021 07:14 AM
I use the following cypher to find recipes by ingredients:
WITH ["Salt","Tomatoes","Pepper"] as ingredients
MATCH (r:Recipe)
WHERE all(i in ingredients WHERE exists(
(r)-[:contains]->(:Ingredient {name: i})))
RETURN r.uid AS recipe
And it works great when the ingredients in the array match exactly, but i want it to work when i have an ingredient name with "10g salt" connected to a recipe.
Any idea how i can implement regex or contains into the cypher?
06-06-2021 10:38 AM
06-06-2021 12:27 PM
Hallo @abhishekjayant1111 ,
thanks for your answer, but i really don't know where to put the CONTAINS inside this query. Could you help me?
06-06-2021 10:32 PM
Hey @ralf.boe, you can try something like this:
WITH ["Salt","Tomatoes","Pepper"] as ingredients
MATCH (r:Recipe)
WHERE all(i CONTAINS 'Salt' WHERE exists(
(r)-[:contains]->(:Ingredient {name: i})))
RETURN r.uid AS recipe
I'm not sure about the above query, but I think regex might be useful in your case.
06-06-2021 10:37 PM
If "10g salt" with lower case 's', then try this:
WITH ["Salt","Tomatoes","Pepper"] as ings
unwind ings as i1
match (a:Recipe)-[:CONTAINS]-(b:Ingredient)
where b.name contains toLower(i1)
return a
06-07-2021 12:51 PM
Thanks for your answer @ameyasoft. The cypher doesn't have any error when executed, but i get no results for it.
06-07-2021 02:38 PM
Post your node with property value = "10g salt". The query worked on my machine and I have a Recipe node with name = "10g salt".
06-09-2021 10:55 AM
Your Cypher is working, but the weird thing is, that it doesn't match when "Salt" is the first word e.g. "Salt and freshly ground black pepper".
And another thing is that i want to match recipes that contain all the ingredients in the ings list. Any idea how to do it?
Thank you!
06-09-2021 12:50 PM
First part:
Try this
WITH ["Salt","Tomatoes","Pepper"] as ings
unwind ings as i1
match (a:Recipe)-[:CONTAINS]-(b:Ingredient)
where toLower(b.name) contains toLower(i1)
return a
All the sessions of the conference are now available online