使用geoflutterfire以及在哪里执行查询

时间:2020-08-30 20:14:12

标签: firebase flutter google-cloud-firestore geolocation

在我的“办公室”集合中,我正在使用GeoFlutterFire软件包尝试查询在x年与y年之间建立的所有办公室,并在距我办公室z英里的范围内提供特定服务。每个“办公室”文档都有一个使用GeoFirePoint的带有geohash和geopoint的“位置”地图,以及一个“建成年份”和“服务”字段。我喜欢进行如下查询,并获取文档并显示它们:

var collRef = firestore.collection('offices')
              .where('service', isEqualTo: 'law')
              .where('built', isLessThanOrEqualTo: y)
              .where('built', isGreaterThanOrEqualTo: x);

geo.collection(collectionRef: collRef.reference())
                .within(center: myOffice, radius: z, field: 'position', strictMode: true);

但这不起作用。我得到一个错误,该查询无效:

Unhandled Exception: PlatformException(invalid_query, FIRInvalidArgumentException, Invalid query. You have a where filter with an inequality (lessThan, lessThanOrEqual, greaterThan, or greaterThanOrEqual) on field 'built' and so you must also use 'built' as your first queryOrderedBy field, but your first queryOrderedBy is currently on field 'position.geohash' instead.)

我知道我们不能对Firebase中的多个字段进行不等式,因为这是索引的工作方式,我想GeoFlutterFire会基于geohash进行内部排序,但是我试图避免客户端查询以避免不必要的文档读取为因此,这就是为什么我需要在这里合并所有查询的原因!

如果我在此处进行位置查询,然后在客户端进行构建年份的查询,最终我会阅读很多不必要的文档。同样的方法也适用于其他方式(基于构建年份和客户端位置的查询)。有办法解决吗?

0 个答案:

没有答案