MichaelSolati / geofirestore-js

Location-based querying and filtering using Firebase Firestore.
https://geofirestore.com
MIT License
505 stars 58 forks source link

Is there any way to do pagination on a certain area? #144

Closed lsps9150414 closed 5 years ago

lsps9150414 commented 5 years ago

I am reading these:

Internally GeoFirestore creates multiple geohashes around a requested area. It queries them and furter calculations on the seperate results are done within the libary. Because of this the additional filtering methods such as orderBy, startAt and endAt can not be passed though GeoFirestore to Cloud Firestore at this time.

Limits on geoqueries are applied based on the distance from the center. Geoqueries require an aggregation of queries. When performing a geoquery the library applies the limit on the client.

So in my use case, the user may have potentially thousands of nearby locations to query and I need a way to paginate them. Does the above information mean that it can't be done?

MichaelSolati commented 5 years ago

Not really, not in a way that would allow skips. On client side you could allow firestore to cache results and slowly expand the radius of the query. But otherwise I would say not really. This is a limitation of how this sort of hashed and aggregated query works.

gauthampait commented 5 years ago

That means every time I increase the radius, it would return me the older set of data, is that correct ? If I am right, is there a way I can pass an inner radius, does that even make sense ?

MichaelSolati commented 5 years ago

You're right in this. Another method you could implement is to use a limit and increase the limit while the radius stays the same. This method can be expensive though as you are reading more docs than you need.

There is no inner radius query function, as implementing that would add a significant weight to the project (it would require hackery, as it's not really how geohashes work)

georgeMorales commented 5 years ago

Two methods would be just as expensive because you are asking for more data than you need, first because you repeat data and the other because you ask for more than you initially need ...

MichaelSolati commented 5 years ago

My concern wasn't about requesting extra data (which is a cost), I was considering the cost of generating these more unique queries.

gauthampait commented 5 years ago

Now that we don't have an available option. I have implemented my search with increasing the radius by 0.15kms. Something I have to live with right now.

I am trying to see if I can read the first set of docs from the cache, and the new paginated data from the server.