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?
Hey @ralf.boe , you can use CONTAINS with the where clause to modify your query. This is the link from the documentation. (check out section 3.3 from this link)
Also, these links might help you with regex in neo4j: link1, link2
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.
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
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