apoc.path.subgraphAll - find nodes with highest pagerank

Hi all, I am running neo4j 4.4 enterprise and having the following issue:

I have an app where users provide a start node and labels of nodes they want to see connected to that start node. They also provide a max number of nodes to return. This boils down to a call to apoc.path.subgraphAll with a config of {limit: <limit>, minLevel: 0, maxLevel: 2, labelFilter: "+<whitelist labels...>", bfs: false}

As you can see, I am using dfs and a maxLevel of 2 so that users can see some interesting paths 2 hops away.

My problem is that I want to be able to show users connected nodes that have the highest pagerank. Effectively, it seems like I want subgraphAll with djikstra's algorithm for search where the weight would be inverse pagerank of the connected node.

Obviously this isn't implemented in APOC, but I have been trying to figure a workaround for this for a few days and not sure what my options are. I've tried taking a larger sample of nodes than I need to, then sorting them and taking the top n nodes, but that is agnostic to the local topology and could end up with me choosing a set of nodes that are two hops away from my startnode and omitting the nodes that connect them.

Anyone have ideas here? Is my only shot to write a stored proc in Java?

I think the GDS BFS and MinimumWeightSpanningTree (inverse of your page-rank) might be useful here?

In principle taking cost properties into account in the apoc path expansion procs would be possible, perhaps you can create a GH issue, but no promises.

Thanks so much Michael! Will leave this unresolved a little longer in case there are any other creative ideas, though I'll be looking into MST