Filter link in relationshipProjection

Hi All

I have success to handle minimal Stp now (neo4j 4.1 with gds) following: Minimum Weight Spanning Tree - Neo4j Graph Data Science
[...
MATCH (n:Place{id: 'D'})
CALL gds.alpha.spanningTree.maximum.write({
nodeProjection: 'Place',
relationshipProjection: {
LINK: {
type: 'LINK',
properties: 'cost'
}
},
startNodeId: id(n),
relationshipWeightProperty: 'cost',
writeProperty: 'MAXST',
weightWriteProperty: 'writeCost'
})
YIELD createMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN createMillis,computeMillis, writeMillis, effectiveNodeCount;
..]
But I would like to run Stp in a set of links relations. How can I filter which links can be used by minimal stp algorithm ? some that allow me to select links (based on properties) to part of relationshipProjection.

Hello Fabio,

Using Cypher projection instead of Native projection is the way to go for you. For this, you need to replace "nodeProjection" and "relationshipProjection" by "nodeQuery" and "relationshipQuery" with some expected returns, see in the code block below. See docs here.

CALL gds.alpha.spanningTree.maximum.write({
    nodeQuery:"MATCH (p:Place) RETURN id(p) as id",
    relationshipQuery: "MATCH (s:Place)-[r:LINK]->(t) WHERE <examplefilter> RETURN id(s) as source, id(t) as target, r.cost as cost",
    relationshipWeightProperty: 'weight',
    writeProperty: 'MAXST',
    weightWriteProperty: 'writeCost'
})
YIELD createMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN createMillis,computeMillis, writeMillis, effectiveNodeCount;

As a side note, you're right, when possible, always use Native projection instead of Cypher projection as it's more efficient ; but in some cases you don't have a choice, e.g. for filters, or when you need some transformation like merging a path into a single relationship.

Hi Marius,

Thanks a lot. Works perfectly. I add only a startNode. again many thanks.