Hi Michael, Product2 contains IngA, IngB, and IngC. Besides Product2, Product1 and Product3 also have the same ingredients.
<https://lh3.googleusercontent.com/-fSN8WowGPZs/WdHBYWu8x3I/AAAAAAAACRc/S4Qj08f0_es089g0bPfCoCIzWm3S5QpXACLcBGAs/s1600/dcgist6.PNG> Your query is showing Product2 and Prduct3 and not Product1. Here is my query: //Find the ingredients for Product2............. MATCH (:Product {name: "Product2"})-[c:CONTAINS]->(i:Ingredient) WITH collect(i) AS ingredients WITH head(ingredients) as first, ingredients //Pick one ingredient from Product2 and find other nodes with the selected ingredient from Product2 MATCH (p)-[:CONTAINS]->(first) WITH ingredients, p UNWIND ingredients as i2 // From the above list of Product nodes match the nodes that contain all the ingredients contained in Product2......... MATCH (p)-[c:CONTAINS]->(i2) RETURn p, c, i2; //RETURN p.name, sum(c.amount) as Tot order by p.name; <https://lh3.googleusercontent.com/-4Roc0bkAXpM/WdHA7nexlzI/AAAAAAAACRU/bPiWuB427WswFBsMHI4g_BuPOtYz3p1JQCLcBGAs/s1600/dcgist7.PNG> <https://lh3.googleusercontent.com/-H1yBA2bl1cU/WdHBAG0ZDfI/AAAAAAAACRY/H8usPyO_A7sTUqyjZceszGHE_w7ijNYbQCLcBGAs/s1600/dcgist8.PNG> Totals match. -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.
