Neo4j Community Server 4.3.3 on Ubuntu 20.04
I have a question I cannot be able to give an answer.
I have the following query:
MATCH (r:Recipe {uuid: '76e9cc6e-fb54-4678-b752-3f420a993653'})<-[d:CAN_BE_SUGGESTED_FOR]-(mention:Mention)
OPTIONAL MATCH (mention)-[:IS_A]-(productType:ProductType)
WITH d, mention, productType
ORDER BY d.distance
WITH d,mention,productType, collect(distinct productType.name) as PTN
return mention.name, productType.name, PTN
With this approach I have the following results, which is not what I need
{
"mention.name": "Santa Maddalena",
"productType.name": "Fermo Rosso",
"PTN": [
"Fermo Rosso"
]
},
{
"mention.name": "Classico",
"productType.name": "Fermo Rosso",
"PTN": [
"Fermo Rosso"
]
},
{
"mention.name": "Classico Chiaretto",
"productType.name": "Fermo Rosato",
"PTN": [
"Fermo Rosato"
]
},
{
"mention.name": "Nebbiolo(Spanna)",
"productType.name": "Fermo Rosso",
"PTN": [
"Fermo Rosso"
]
},
{
"mention.name": "Frizzante",
"productType.name": "Mosso Rosso"
"PTN": [
"Mosso Rosso"
]
}
What I need, Iis to have one result containing the following two sub Items:
The first:
{
"mention.name": "Santa Maddalena",
"productType.name": "Fermo Rosso"
},
{
"mention.name": "Classico",
"productType.name": "Fermo Rosso"
},
{
"mention.name": "Classico Chiaretto",
"productType.name": "Fermo Rosato",
},
{
"mention.name": "Nebbiolo(Spanna)",
"productType.name": "Fermo Rosso"
},
{
"mention.name": "Frizzante",
"productType.name": "Mosso Rosso"
]
And the second
"PTN": [
"Fermo Rosso","Fermo Rosato","Mosso Rosso"
]
where the order of the PTN content is the same as in the first query result.
I hope to have been able to explain the problem.
Thank you