【问题标题】:GeoFire orderByChild filteringGeoFire orderByChild 过滤
【发布时间】:2018-09-26 19:09:44
【问题描述】:

我似乎偶然发现了 GeoFire 的一个问题,因为我似乎无法过滤我的 GeoFire 查询。在我的平台上,用户创建帖子并使用 geofire 设置他们的位置,因此,可能有成千上万的帖子我不想在客户端过滤..

我想orderByChild('created')limitToLast('10') 这样在客户端不需要太长时间..

到目前为止我所拥有的是:

  this.geoFire = new GeoFire(this.database.database.ref()
  .child('location'))
  this.geoFire.query({
    center: [this.userLocation.lat, this.userLocation.lng],
    radius: 7
  })
  .on('key_entered', (key, location, distance) => {
    this.subscription = this.database.database.ref('/posts/'+key)
    .orderByChild('created')
    this.subscription.once('value', (snapshot) => {
          this.postFeed.push(snapshot.val())
    });
  })

但这似乎不起作用。

我的位置数据库如下所示:

对于帖子:

我做错了什么?为什么我不能过滤orderByChild('score') or 'created'

【问题讨论】:

    标签: javascript angular firebase geofire


    【解决方案1】:

    Firebase 查询根据您指定的条件从特定位置检索(可能)多个子节点。您已经在此处获得了帖子的完整路径:database.ref('/posts/'+key)。您不能将已经知道要检索的帖子与根据条件查询帖子结合起来。

    您最好的办法是检索范围内的所有帖子,然后过滤客户端上前 10 个最近的帖子。

    【讨论】:

    • 这看起来效率很低,不是吗?如果在 5 英里半径范围内有 10-20,000 个帖子,那将需要一段时间......不是吗?
    • 是的。另一种方法是根据帖子的新近度保留多个地理索引。 Geofire 已经通过过滤两个值来做一些非常神奇的事情,这在 Firebase 中通常是不可能的。您正在尝试在组合中添加另一个值(新近度),这超出了该库的用途。
    猜你喜欢
    • 1970-01-01
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多