Using a SearchView to search in Firebase [duplicate] - android

I need to fetch list of users from Firebase database using SeachView or search dialog and I think word stemming will be best for my app.
Not asking for code but please tell me the alorigthm for it.

To achieve what you want, you need to execute a query which should look like this:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usersRef = rootRef.child("users");
Query query = usersRef.orderByChild("name").equalTo(newText);
So everytime you create a search you should return a new query. So according to this, every time you want to filter on a new condition, you will need to:
Create a new query based on the new filter:
Query query = usersRef.orderByChild("name").equalTo(newText);
Attach a listener to this new created query.
Create a new adapter with the results of this new created query, or update the existing one using notifydatasetchanged() method.

Related

How to implement BETWEEN Sql query in Firebase?

I am working on a android Firebase project. I need help in implementing this sql query in Firebase real-time database.
SELECT * FROM table
WHERE price BETWEEN $min AND $max;
There's good documentation on how to do firebase queries as well as apply them to ranges.
Something like:
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("table");
Query query = ref.orderByChild("price").startAt(min).endAt(max);
Then you add the appropriate listener for what you are trying to do. (e.g. a ValueEventListener or a ChildEventListener via addValueEventListener or addChildEventListener respectively.
You can use the following method
new Firebase("https://examples-sql-queries.firebaseio.com/messages")
.startAt(startTime)
.endAt(endTime)
.once('value', function(snap) {
console.log('messages in range', snap.val());
});

Kotlin Firestore Queries Issue

Im using FirestorePagingAdapter in the FireStoreUI framework to create a simple query and get results into a recycler view.
I am able to fetch results and display them if I use a simple query:
var mQuery = FirebaseFirestore.getInstance().collection("test")
But in my application I have a searchView which I will be using to add queries options in mQuery eg:
var mQuery : Query = FirebaseFirestore.getInstance().collection("test")
if (!searchString.isNullOrEmpty()) {
println("SearchView: $searchString")
mQuery.whereGreaterThanOrEqualTo("name", searchString)
}
But this does not work.
Can we not add options to Query after it has been assigned?
Query objects are immutable. They can't be changed after created. Notice from the API documentation that whereGreaterThanOrEqualTo() returns a new Query object (as well as all filters) with the new condition added to it. So, you can just reassign mQuery with the new Query it built.
See also: Conditional where clause in firestore queries

Applying Word Stemming in SearchView for fetch data from Firebase database

I need to fetch list of users from Firebase database using SeachView or search dialog and I think word stemming will be best for my app.
Not asking for code but please tell me the alorigthm for it.
To achieve what you want, you need to execute a query which should look like this:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usersRef = rootRef.child("users");
Query query = usersRef.orderByChild("name").equalTo(newText);
So everytime you create a search you should return a new query. So according to this, every time you want to filter on a new condition, you will need to:
Create a new query based on the new filter:
Query query = usersRef.orderByChild("name").equalTo(newText);
Attach a listener to this new created query.
Create a new adapter with the results of this new created query, or update the existing one using notifydatasetchanged() method.

Firebase Query in android app ,multiple order by need to work

I am using Firebase realtime DB in my app,I could not use multiple order by in my query.If i am not use that one,looping the data again and again.It leads my app run slow.So please help me how to do that.Otherwise how to get multiple items in single Query
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
Query query = reference.child("issue").orderByChild("id").equalTo(0,1,3);
...Like,is it possible????

Getting the data from firebase database based on conditions

This is the link for image
I want to get the msg from the above data where sender equals to salam..can any body help me out how to write query in firebase database(Android)..I am new to this firebase..
The query will be pretty straightforward, but there are multiple ways you can implement the query listeners depending on your use case. If you only want to read your data once, you can setup the following query.
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
ref.child("messages").orderByChild("sender").equals("salam")
.addListenerForSingleValueEvent(new ValueEventListener({...}));
See https://firebase.google.com/docs/database/android/read-and-write for the startup tutorial and https://firebase.google.com/docs/reference/android/com/google/firebase/database/DatabaseReference for the full documentation.

Categories

Resources