GeoFlutterFire icon indicating copy to clipboard operation
GeoFlutterFire copied to clipboard

Issue when using limit(1)

Open momoDragon opened this issue 5 years ago • 8 comments

I have 2 orders Available

Order A is geohash "w0zqfx9ne" geopoint [5.4475907° N, 100.3067173° E]

Order B is geohash "w0zq3cprf" geopoint [5.3242402° N, 100.2822717° E]

My Position is lat: 5.4375 long: 100.3095

stream = geo.collection(collectionRef: Firebase.instance.collection('orders').where('orderStatus', isEqualTo: 1) .limit(1)).within( center: geoCenter.point( latitude: myPosition.latitude, longitude: myPosition.longitude), radius: 10, field: field, strictMode: true);

What Dosent work: When both orderStatus is equal to 1. I get back no documents When orderStatus of A is set to 2, i get back no documents.

What Works: When i change order B's orderStatus to 2, i get back order A. When both order status are 1 and i set limit(2), i get back order A

Expected result: Getting back document of Order A

My position to order B is 12.95 KM. I am not sure why its affecting the query.

Please test it out with the coordinates and hashes i listed. This is weird behavior.

momoDragon avatar May 04 '19 15:05 momoDragon

Hey @momoDragon this library doesn't support limit() and sortBy(), in case you use limit() it'll run limit on all 9 queries individually. This was discussed on other threads as well. I'll keep the docs updated, sorry about that!

DarshanGowda0 avatar May 04 '19 18:05 DarshanGowda0

This should give you a better explanation.

DarshanGowda0 avatar May 04 '19 19:05 DarshanGowda0

Whats the best way to make a query like uber where we only get one document back in a 10km radius when there are multiple docs present ?

momoDragon avatar May 05 '19 03:05 momoDragon

There's no way to set a hard limit in this library as explained in #21, the best alternative would be to set limit(1) on your query, which would read 1 doc from all geohashes, giving you 9 reads.

DarshanGowda0 avatar May 05 '19 15:05 DarshanGowda0

So even if i dont get anything back it will charge me 9 reads?

momoDragon avatar May 06 '19 05:05 momoDragon

Hey @momoDragon! I believe yes, you'll be charged at least once per query even if you don't get back any results as mentioned in the cloud_firestore docs - https://firebase.google.com/docs/firestore/pricing#minimum-charge

DarshanGowda0 avatar May 06 '19 06:05 DarshanGowda0

Do u think u can make a query that increases range automatically to get 1 doc? so like if radius is set to 10, it will query at 2km, 4km, 6km, 8km, 10km. And if at 2km there is an item, it will stop the query there. if there is none it will increase radius till 10. Because currently its impossible to use limit(1) because like the case i stated above, if there is an item at the corner of the geo hash box, but its not in the radius, it wont return anything because its in the box but out of radius.

momoDragon avatar May 22 '19 04:05 momoDragon

@momoDragon to access the doc in the neighboring geohash box and not inside radius you can set the strictMode to false! And the requirement you stated can be done using RxDart operators on the application side itself.

DarshanGowda0 avatar May 23 '19 07:05 DarshanGowda0