Hi David,

I read your GraphGist and here are my suggestions:

Query 3/5:

MATCH (p1:Product {name: "Product3"})-[c1:CONTAINS]->(i:Ingredient)
WITH collect(i.name) AS i1, c1.amount AS amount, c1.amount + 6 AS 
amountHigh, c1.amount - 6 AS amountLow 

MATCH (p2)-[c3:CONTAINS]-(i2) WHERE amountLow < c3.amount < amountHigh
WITH p2 as p3,c3,i2,  collect(i2.name) as matched, i1 WHERE ALL(x in i1 
WHERE x in matched)
RETURN p3, c3, i2
//RETURN p3.name, sum(c3.amount) as Tot order by p3.name;

<https://lh3.googleusercontent.com/-wjzFShMzvkU/Wc_snU1U45I/AAAAAAAACQw/OjbSkAKocnsjfV-PSgTTbAvER-SpSsY_wCLcBGAs/s1600/dcgist2.PNG>


<https://lh3.googleusercontent.com/-qEKWiEPXZ9E/Wc_stOB5t3I/AAAAAAAACQ0/2U7YaJtE-RIjTEn1fHw7oMj2-iuSHj6cQCLcBGAs/s1600/dcgist3.PNG>
Totals are correct.

In general we can select amount ranges by specifying the numbers:

MATCH (p1:Product)-[c1:CONTAINS]->(i1:Ingredient)
WHERE c1.amount < 25
//RETURN p1.name,sum(c1.amount) as Tot
RETURN p1, c1, i1;

<https://lh3.googleusercontent.com/-yqczBetOEhA/Wc_uB-DKSoI/AAAAAAAACRA/gIICWTvyv14ZAfqa7RnyX_puKYNGzXLZACLcBGAs/s1600/dcgist4.PNG>

<https://lh3.googleusercontent.com/-MrC01i0dTkE/Wc_uEzsWjtI/AAAAAAAACRE/Oiy3eRsVacA-_gA703_m_WGwn09Ko24hgCLcBGAs/s1600/dcgist5.PNG>

Thanks,
-Kamal
 

On Thursday, September 14, 2017 at 4:31:42 AM UTC-7, 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