Ok have found the error with the first query

MATCH (p1:Product {name: "P1"})-[c:CONTAINS]-(i:Ingredient) WITH collect(i.
name) as i1 MATCH (p2:Product)-[:CONTAINS]-(i2) WITH p2, collect(i2.name) as 
matched, i1 WHERE ALL(x in i1 WHERE x in matched) return p2

I was not declaring the parameter name in the collect i2

Now to try and work out if there is a way of completing the 2nd query, is a 
FOREACH loop likely to work here?

On Thursday, 14 September 2017 12:31:42 UTC+1, Dave Clissold wrote:
>
> Hi All
>
>
> I am trying to match a product against multiple ingredients, the returned 
> node must contain all of the ingredients, sometimes there is a quantity of 
> how much of an ingredient is used. The number of ingredients can change, so 
> using an array is preferred, but this is part of an API project being built 
> in javascript so we can use FOR IN loops etc if it makes things easier.  As 
> an example I've set up this in the console  
> http://console.neo4j.org/?id=39ead
>
>
> I have 2 ways of querying that I cannot solve
>
>
> *1.*
>
>
>  When running a WHERE IN query, like this one below
>
>
> MATCH (p:Product)-[:CONTAINS]-(i:Ingredient) WHERE i.name IN['D','E','F'] 
> RETURN p
>
>
> It will treat the IN statement as an OR match against D, E or F and return 
> all :Products that contains these, in example (P1, P3, P4), is there a way 
> to declare this as AND, so the match is against D, E and F, so that it only 
> returns products that Contain all of these (P3, P4). I had found this post 
> on StackOverflow, 
> https://stackoverflow.com/questions/25939493/neo4j-match-multiple-destination-nodes
>  which 
> lead me to trying this query but it returns no rows
>
> MATCH (p1:Product {name: "P3"})-[c:CONTAINS]-(i:Ingredient) WITH collect(i
> .name) as i1, c MATCH (b:Product)-[:CONTAINS]-(i2:Ingredients) WITH b, i1, 
> i2, c, collect(i2) as matched2 WHERE ALL(x IN i1 WHERE x in matched2) 
> RETURN b
>
>
> *2.*
>
>
> When there is a value of amount is there a way to run a similar query, but 
> also match a parameter from the relationship as below,
>
>
> MATCH (p1:Product {name: "p2"})-[c1:CONTAINS]-(i1:Ingredient)
> WITH c1 - 5 AS amountLow, c1 + 5 as amountHigh, i1
> MATCH (p2:Product)-[c2:CONTAINS]-(i2:Ingredient) WHERE i2.name = i1 AND 
> amountLow < c2.amount < amountHigh
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to