0

I have a document collection of members which have two relevant properties: _key and score. I've also created a persistent index on the score field, as that should make sorting significantly faster. I want to write an AQL query that returns different results based on the sorted index of a specific member (referred to as A):

  • Always returns at least the top 5 members by score. (LIMIT 5)
  • If A is in the top 10, return the 6 - 10 ranked members. (LIMIT 5, 5)
  • Otherwise, return the members directly above and below A in rank. (LIMIT x - 1, 3, x = A's rank)
ElJay
  • 347
  • 4
  • 17

1 Answers1

0

I was unable to do this in a single query, however I was able to fetch the rank of a member by doing something along the lines of

RETURN LENGTH(
  FOR m IN members
    FILTER m.score > DOCUMENT("members", "ID").score
    RETURN 1
) + 1

and then use a second query to fetch the ranked data I wanted, something like

  FOR m IN members
    SORT m.score DESC LIMIT 10
    RETURN m

or joining two sub-queries with LIMIT 5 and LIMIT rank - 2, 3 depending on the rank.

ElJay
  • 347
  • 4
  • 17