I am new to Firebase. I am currently making and android application that is basically a property renting app. I want to make a query to filter a property. I want to search based on the users input. Also search when user leave the input blank. So when the user only inputs the price, it searches all the rooms, cr and pets.
-
2Welcome to Stack Overflow. I would suggest that you study the documentation https://firebase.google.com/docs/database/android/start/ and in case you encounter precise problems, you modify your question with explaining the exact problem and the code you have already tried. You may also read this: https://stackoverflow.com/help/how-to-ask – Renaud Tarnec Apr 23 '18 at 16:11
-
1Which database? Realtime or Firestore? – Greg432 Apr 23 '18 at 16:12
-
1It is Realtime. – Cj Zayin Queenie Cabug-os Apr 23 '18 at 16:18
1 Answers
For what you want to do I would use Cloud Firestore Database and NOT a realtime, as Firestore was built for that type of stuff. Plus its easier to read. Also I would like to point out that Cloud Firestore is a Realtime Datebase just more SQL like.
This is a sample for Cloud Firestore, but the code is very simple to write. I'm sure the Realtime database can do something similar but you will spend alot more time writing code to get it to work the way you want. Trust me.
// Create a reference to the cities collection
CollectionReference housesRef = db.collection("houses");
// Create a query against the collection.
housesRef.whereEqualTo("availability", "yes").whereEqualTo("pets", "yes");
https://firebase.google.com/docs/firestore/query-data/queries
Also, as far as I know, you can not do that much server side querying with a realtime database so if you were to have a filter feature, most likely that would be done on the client side of things, which is slow and takes time. The app would have to read the data using a loop, checking each element to see if it met the requirements, that works if you have 10 or 20 houses but after a certain point that will cause lag.
Realtime Database is Firebase's original database. It's an efficient, low-latency solution for mobile apps that require synced states across clients in realtime.
Cloud Firestore is Firebase's new flagship database for mobile app development. It improves on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales better than the Realtime Database.
-
1Yes, I think the queries in Firebase realtime databe is limited, that is why I am having confusion. I just thought someone might have encountered and found a solution using Firebase. Because the problem is I already established Realtime database in the app, most of the code is in Realttime database. I was looking for something without causing too much alteration in the app. I came across with ElasticSearch, which support queries like this, but I want to do everything with Firebase. Thank you so much for this. I think Firestore seems better option for the app. – Cj Zayin Queenie Cabug-os Apr 23 '18 at 17:01
-
@CjZayinQueenieCabug-os https://stackoverflow.com/questions/34537369/how-to-search-for-a-value-in-firebase-android – Peter Haddad Apr 23 '18 at 17:03