I have a graph with spatial data using the spatial plugin.
This graph has \"Threat Zones\" (Polygons) which can be on top of the other so they also have a z-index proper
I think you are looking for an "arg max" style query. In this case, using collect is the way to go:
MATCH (asset:Asset {name:'Asset Name'})-[]-(ara:AssetRiskAssessment)
WITH asset, ara
CALL spatial.intersects('threat_zones',asset.wkt) YIELD node
WITH node, asset, ara
MATCH (node)<-[:FOR]-(tss:ThreatScenarioScore)-[]-(ts:ThreatScenario)
WITH node, tss, ts
ORDER BY ts.name ASC, node.zindex DESC
WITH
ts.name AS name,
collect({
zindex: node.zindex, intention: tss.intention, capability: tss.capability
})[0] AS max
RETURN
name,
max.zindex AS zindex,
max.intention AS intention,
max.capability AS capability
This sorts the tuples according to their name
(ascending), but more importantly, according to their zindex
in a descending order. So when the zindex
and tss
properties are collected to a list, the first item (index [0]
) will hold the elements with the maximum zindex
value.