In my "offices" collection, I am using GeoFlutterFire package trying to query all the offices built between year x and y, offering a specific service and within z miles of my office. Each "office" document has a "position" map with geohash and geopoint using GeoFirePoint, plus a "built year" and a "service" field. I like to do a query like below and get the documents and display them:
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);
But this does not work. I get an error that this query is invalid:
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.)
I know we can't do inequality for more than one field in Firebase since that's how indices work and I guess GeoFlutterFire does an internal sorting based on geohash, but I am trying to avoid client side queries to avoid unnecessary document reads as much as possible, so that's why I need to combine all the queries here!
If I do the location query here and then do the built year on client side, I will end up reading a lot of unnecessary documents. Same applies the other way around (querying based on built year and handle location on client side). Is there a way around this?