// Query 1
MATCH (sport:Sport{uuid: "golf"})
MATCH (sport)-[:HAS_NAME]->(sportNames:Name)-[:FOR_LANGUAGE]->(language: Language)
WHERE language.uuid IN ["English", "Polish"]
WITH sport, collect({name: sportNames.name, language: language.uuid }) AS translatedNames
RETURN { uuid: sport.uuid, translatedNames: translatedNames }
// Query 2
MATCH (sport:Sport{uuid: "golf"})
MATCH (sport)-[:HAS_NAME]->(sportNames:Name)-[:FOR_LANGUAGE]->(language: Language)
WHERE language.uuid IN ["Polish", "English"]
WITH sport, collect({name: sportNames.name, language: language.uuid }) AS translatedNames
RETURN { uuid: sport.uuid, translatedNames: translatedNames }
the order of translatedNames are same in response whereas in the WHERE statement I updated the order. How to make it work?
The order of the results returns is most likely the order in which the paths were found. This would not be dependent on the order of your list in your predicate. You will need to sort the results before returning them if order matters.
The following would work if natural ordering is it. If you had more than two languages and you wanted a custom ordering, you could define a ranking with a case statement.
MATCH (sport)-[:HAS_NAME]->(sportNames:Name)-[:FOR_LANGUAGE]->(language: Language)
WHERE language.uuid IN ["Polish", "English"]
WITH sport, sportNames, language
Order by language.uuid
WITH sport, collect({name: sportNames.name, language: language.uuid }) AS translatedNames
RETURN { uuid: sport.uuid, translatedNames: translatedNames }
Note, order by is ascending by default. You can add βdescβ to change the ordering.
1 Like