suiko1984 / geofirestore-android

GeoFire for Android - Realtime location queries with Firebase Cloud Firestore
13 stars 4 forks source link

Compound query not working for "whereEqualTo" #14

Open cbarrios opened 4 years ago

cbarrios commented 4 years ago

Hi I recently tested this library for compound query but this is not working for me. geoFire = new GeoFire(ref,ref.whereEqualTo("method","manual"));

However, using limit does work and removing that "ref.whereEqualTo("method","manual")" and simply leaving it as geoFire = new GeoFire(ref) does retrieve all docs.

Is there any thing I could be missing? Please help.

suiko1984 commented 4 years ago

Hi @cbarrios I have tested your scenario but It seems to be working. Can you please tell me what listener do you use to retrieve the documents? With thanks.

cbarrios commented 4 years ago

Hi Here is my code: private CollectionReference ref = null; private GeoFire geoFire = null; ref = FirebaseFirestore.getInstance().collection("methods"); geoFire = new GeoFire(ref,ref.whereEqualTo("method","manual")); ` public void newListener(GeoPoint geoPoint){ count = 0; com.koalap.geofirestore.GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(geoPoint.getLatitude(),geoPoint.getLongitude()),2); geoQuery.addGeoQueryDataEventListener(new com.koalap.geofirestore.GeoQueryDataEventListener() { @Override public void onDataEntered(DocumentSnapshot documentSnapshot, GeoLocation location) { count++; counter.setText(""+count); }

        @Override
        public void onDataExited(DocumentSnapshot documentSnapshot) {

        }

        @Override
        public void onDataMoved(DocumentSnapshot documentSnapshot, GeoLocation location) {

        }

        @Override
        public void onDataChanged(DocumentSnapshot documentSnapshot, GeoLocation location) {

        }

        @Override
        public void onGeoQueryReady() {

        }

        @Override
        public void onGeoQueryError(Exception error) {

        }
    });
}`
suiko1984 commented 4 years ago

@cbarrios Can I get the location of your geoPoint and a screenshot of your "methods" collection on Firebase console

cbarrios commented 4 years ago

Hey. This is All I got on firebase: docId: F2S1xAMUbYqCMJoVHFtU g: dhwf67zmy9 l: 25.72959987419827, -80.39869219064713 method: "manual"

Assume the geoPoint is the same as this one. Cause again, it does retrieve them. It just does not work when I add the query. The method field is a string field with a string value.

I am also using this dependency: implementation 'com.google.firebase:firebase-firestore:21.4.3'

To be exact this is my actual geoPoint: latitude: 25.7311017, longitude: -80.3966983

suiko1984 commented 4 years ago

I exactly have the same data but the "onDataEntered" is triggered. Please confirm that :

cbarrios commented 4 years ago

Yes, finally was able to get it after creating a COMPOSITE INDEX on firebase console with field method Ascending and g Ascending. This is very important step. Otherwise it won't work. So the key is to include the field(s) in your "whereEqualTo" clause plus the "g" field both Ascending in a composite index. I believe including this specific step would help new testers of the library. Thank you.

cbarrios commented 4 years ago

Also, is there any way of supporting the query clause "whereGreaterThan" in the near future or is it impossible due to the limitations on firestore? This would be great to have to filter even more.

KelvinPac commented 4 years ago

@suiko1984 Is it possible to throw an error on the library when indexes are not created? I just spent 2hrs debugging that issue on a build. Too bad I was filtering the wrong tags on the logcat

suiko1984 commented 4 years ago

@cbarrios It is at the moment impossible due to Firestore limitations. Please read this lines : https://firebase.google.com/docs/firestore/query-data/queries?authuser=0#query_limitations

@KelvinPac Strangely I got the exceptions : Caused by: io.grpc.StatusException: FAILED_PRECONDITION: The query requires an index. You can create it here: https://console.firebase.google.com/v1/r/project/...