Summing the weights of the edges

I have a vertex p of type person which is connected to multiple vertices of type image by some edge (type and attributed are irrelevant), and I’m trying to select a subset of images. Now there is also a map M of type (string -> float) which has an entry for every vertex of another type theme (theme has a string attribute name, which constitutes the keys of the map M), and each image is connected to each theme by an edge belongs. The edge belongs has an attribute similarity, and the rank of an image vertex is determined by multiplying each similarity value corresponding to the appropriate value in M.

For example, John is connected to image1 and image2. There are 2 themes, sports, and history, and each image has a belongs connection to each theme (so 4 belongs edges total, each with a similarity attribute). M then has 2 entries with keys sports and history. My goal is to choose one image (for the sake of simplicity; in actuality I’ll limit to some pre-determined number probably other than 1). The rating of image1 can be determined by multiplying M[sports] by the similarity between image1 and sports, then similarly for history, and finally adding the two products together. So the select is ordered by that sum, and limited to 1.

I want to avoid multiple hop patterns with v2 since the docs indicate that distributed queries don’t allow access to aliases between the outer vertices, which wouldn’t work for this problem. My first instinct using v1 syntax is to have a ListAccum<vertex> which is populated with a select on p-(likes>)-image, then a MapAccum<string, MapAccum<string, float>> populated by a loop over that list, then a select on image-(belongs>)-theme on each, so each image ID is mapped to a map, and in that inner-map, each category is mapped to the similarity value. That would require another select on p-(likes>)-image after, that one ordering and limiting. But this seems very inefficient, so does any easier and/or more efficient solution come to mind?

TL;DR If I have a vertex A connected to some set of vertices B, and each of those connected to another set of vertices C, then how can I select a subset of B ordering by summing the weights of the edges BC?

Original question asked by @shriggy in the community chat.