kosukesaigusa / geoflutterfire_plus

🌍💙🔥 geoflutterfire_plus allows your flutter apps to query geographic data saved in Cloud Firestore. This package is fork from GeoFlutterFire, and tried to be constantly maintained to work with latest Flutter SDK, Dart SDK, and other dependency packages.
https://pub.dev/packages/geoflutterfire_plus
MIT License
59 stars 7 forks source link

How many documents are queried? #207

Open itismejy opened 4 months ago

itismejy commented 4 months ago

In the documentation:

🚨 Limitation: currently limit and orderBy queries are not supported because of the geo hash query algorithm and Cloud Firestore query limitations. Alternatively documents can be sorted on client side after getting the data (documents).

I would like to ask, how many documents are queried maximum?

kosukesaigusa commented 4 months ago

@itismejy

how many documents are queried maximum?

Do you want to ask how many documents are retrieved at maximum as geoflutterfire_plus queries?

The maxim number is not set by geoflutterfire_plus package, but for now you can't set orderBy to your query, so even if you set limit to your query, it might not work as you expect.

itismejy commented 4 months ago

Hi there, I was wondering if this is possible?

https://stackoverflow.com/questions/62175796/limit-the-retrieve-of-documents-from-firebase-on-flutter Query query = cities.orderBy("name").limit(3); // descending order

Query query = cities.whereGreaterThan("population", 2500000L).orderBy("population").limit(2); // ascending order

In your code for geoflutterfire_plus, i see this: @visibleForTesting Query geoQuery({ required final String field, final String geohashField = 'geohash', required final String geohash, final Query? Function(Query query)? queryBuilder, }) { Query query = _collectionReference; if (queryBuilder != null) { query = queryBuilder(query)!; } return query .orderBy('$field.$geohashField').limit(5) // add the limit here, and alllow user to pass it as a parameter .startAt([geohash]).endAt(['$geohash$_rangeQueryEndAtCharacter']); }

I see you are doing the query with cloud firestore https://firebase.google.com/docs/firestore/query-data/order-limit-data#dart in their docs they do this: final citiesRef = db.collection("cities"); citiesRef.orderBy("name").limit(3);

Could the query be changed to: query.where('$field.$geohashField', isGreaterThan: geohash, .orderBy('$field.$geohashField').limit(5); // add the limit here, and alllow user to pass it as a parameter

kosukesaigusa commented 4 months ago

@itismejy

It is possible to add .limit(N) to your query, and it certainly returns N or less documents.

However, you can't set orderBy to your query, so the result might not work as you expect in terms of its order (it is not possible to get to know which N documents are retrieved from the query).

bw-flagship commented 4 months ago

Maybe we could change the docs of this page. It says

🚨 Limitation: currently limit and orderBy queries are not supported because of the geo hash query algorithm and Cloud Firestore query limitations. Alternatively documents can be sorted on client side after getting the data (documents).

After reading this thread it makes sense, but on my first read I thought that limit-queries (without orderBy) aren't supported either.

kosukesaigusa commented 3 months ago

@bw-flagship

Thank you! I'll think about updating README to avoid confusion!