How to Rank a list of UIDs by connections to a given UID

What I want to do

Given a list of UIDs preferably from a var block, rank/order them by the ones most connected to a given UID

The concept is to allow users to have a profile that they then tag and add relationships to other profiles. Then the users wants to apply some set of filters to profiles and find the ones that are most like their own by terms of common connections.

What I did

Right now I can apply a set of filters, but I don’t have any way to better rank them than what is available to order by in the basic GraphQL query for that type which is very limited.

  profiles(func: eq(xid,["Bar","Baz","Qux"])) {
    # need to rank these be their commonalities to xid:Foo

An Example

Given these data points and relationships:

Data Sample
  _:Foo <parent> _:Bar .
  _:Baz <parent> _:Bar .
  _:Bar <children> [_:Foo, _:Baz] .
  _:Foo <tags> [_:tag1, _:tag2, _:tag3, _:tag4] .
  _:Qux <tags> [_:tag1, _:tag2, _:tag3] .
  _:tag1 <tagged> [_:Foo, _:Qux] .
  _:tag2 <tagged> [_:Foo, _:Qux] .
  _:tag3 <tagged> [_:Foo, _:Qux] .
  _:tag4 <tagged> [_:Foo] .
  _:Foo <state> _:stateA .
  _:Bar <state> _:stateA .
  _:stateA <residents> [_:Foo, _:Bar] .

If from the perspective of _:Foo I wanted to query for [’:Bar’,’:Baz’,’_:Qux’] I would want order of:

  1. Qux [3 points] (shares _:tag1),(shares _:tag2),(shares _:tag3)
  2. Bar [2 points] (is _:parent),(shares _:stateA)
  3. Baz [1 point] (shares parent of _:Bar)

More context

I have a list of around 13K locations on a map that my UI cannot handle so I need to reduce it down to the top ~15 based on some sort of ranking. If I just stick to the default pagination (by uid), The first 15 may be utterly useless. There is nothing really in ordering in the nodes themselves that gives much of any value for an order as all of the value is in the nested edges. I.E. friends of friends etc.