有没有办法在 RethinkDB 的过滤器上查询最近的位置?

Is there a way to query the closest locations on a filter in RethinkDB?

目前,Rethink API documentation 表示 get_nearest 命令仅适用于 table。当然我可以事后过滤结果,但这似乎效率低下,而且当我想将结果限制为特定数量的项目时,需要将所有项目按距离排序。

有没有一种方法可以让我在一次查询中从过滤列表中获得最接近的结果?

它只适用于 table 的原因是强制索引。索引仅适用于 table 级别。仔细想想,这是有道理的,因为它是一个昂贵的查询。

但是,如果您有过滤列表,最好的办法是使用 distance 并按其结果排序。

像这样的东西会起作用:

r.db('db').table('table')
  .filter(function_to_filter)
  .orderBy(function(doc) {
    return r.distance('your_point_to_compare', doc('point'))
  })