Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-28-2022 12:49 AM
Hi Team i have a query that i want to execute with different parameters values and return all the results on a same return .
MATCH (h1:Hexagon{indexOrder:0})-[:HAS_ANSWER]->(a1)<-[:CHOOSE]-(p:Profile{id:'1'})-[:CHOOSE]->(a2)<-[:HAS_ANSWER]-(h2:Hexagon{indexOrder:1})
with a1 , a2, p
OPTIONAL MATCH (a1)<-[:CHOOSE]-(p2:Profile)
WHERE p2<>p
WITH count(a1) as a1c , p2 , a2
OPTIONAL MATCH (a2)<-[:CHOOSE]-(p2:Profile)
WITH a1c , p2, count(a2) as a2c
RETURN p2, a1c + a2c as coincidences
I want to get the result for
h1:Hexagon{indexOrder:0} and h2:Hexagon{indexOrder:1}
h1:Hexagon{indexOrder:1} and h2:Hexagon{indexOrder:2}
h1:Hexagon{indexOrder:2} and h2:Hexagon{indexOrder:3}
h1:Hexagon{indexOrder:3} and h2:Hexagon{indexOrder:4}
h1:Hexagon{indexOrder:4} and h2:Hexagon{indexOrder:5}
h1:Hexagon{indexOrder:5} and h2:Hexagon{indexOrder:6}
Is there a method that i can use to display all this result on only one query? because actually i send 6 query to neo4j from my backend to get the data i need, but i want to only send 1 query and return all the results that i need
Greetings from Mexico
04-28-2022 02:56 AM
Try:
UNWIND [0, 1, 2, 3, 4, 5] as indexOrder
MATCH (h1:Hexagon{indexOrder: indexOrder})-[:HAS_ANSWER]->(a1)<-[:CHOOSE]-(p:Profile{id:'1'})-[:CHOOSE]->(a2)<-[:HAS_ANSWER]-(h2:Hexagon{indexOrder: indexOrder + 1})
with a1 , a2, p
OPTIONAL MATCH (a1)<-[:CHOOSE]-(p2:Profile)
WHERE p2<>p
WITH count(a1) as a1c , p2 , a2
OPTIONAL MATCH (a2)<-[:CHOOSE]-(p2:Profile)
WITH a1c , p2, count(a2) as a2c
RETURN p2, a1c + a2c as coincidences
You can pass the indexOrder through your chain of ‘WITH’ clauses and include it in your return statement if you want each result to be labeled with its corresponding indexOrder.
All the sessions of the conference are now available online