While working on approximate string matching (https://stackoverflow.com/q/58065020/140837) I stumbled upon the need to lookup the nearest keys around an input key. Hence the idea to have a fdb.range_near(key, limit).
A workaround could be the query by prefixes of key of decreasing length until reaching limit found keys or the empty prefix. That seems like a waste because results of db.range_prefix(key[:len(key) - n] are included in db.range_prefix(key[:len(key) - n - 1] (where n is strictly bigger than the length of the associated subspace prefix)
Would something like key-selectors help? For your previous example, we could fetch n/2 keys above and n/2 below the pivot key and then do another call to make up for any shortfall.
That will not necessarily be the nearest keys. To be sure, that the returned keys are the nearest, one will need to fetch LIMIT keys above and LIMIT keys below, and compute the nearest keys. That is not bad. In my case, LIMIT is not more than 10.
(By the way, I am still not sure about the “approximate string matching” algorithm I wrote about in the original post).
Yes, if there is a notion of ‘nearness’ then one would need to fetch n keys on each side. I was trying to fetch n keys ‘around’ the pivot key, as mentioned in the example. I will read the original post more carefully and see if there is anything possible for it.