Android | IOS using firebase database with search for specific items + Pagination

170 views
Skip to first unread message

Mohammed Riyadh

unread,
Apr 29, 2017, 10:44:29 AM4/29/17
to Firebase Google Group
Hi every 1,

I'm using firebase in my project which will have as expected a lot of users data what i need to implement is user search for specific item name and to paginate the search results at the same time.
I know that firebase has some limitation with the querying side so i hope that some 1 has some ideas .

the issue is the searching query using below code :

FIRDatabase.database().reference().child("search").queryOrdered(byChild: "name").queryStarting(atValue: searchtv.text!).queryEnding(atValue:  searchtv.text!+"\u{f8ff}").observe(.value ,with: { (snapshot) in  ....  

and the pagination query is like below : 

First Time data loading :


var objectsperpage : UInt = 3


ref
.queryOrderedByKey().queryLimited(toLast: objectsperpage).observe(.value, with: { (snapshot) in .....

self.lastkey = (Array(snapshot.children).first as AnyObject).key


and to load more data :

 ref.queryOrderedByKey().queryLimited(toLast: objectsperpage + 1).queryEnding(atValue: lastkey).observe(.value, with: { (snapshot) in....


Is there any way to do both queries at the same time ?

Thanks in advance


 

Kato Richardson

unread,
May 1, 2017, 3:41:34 PM5/1/17
to Firebase Google Group

Hi Mohammed,

You can add a child key into the queryEndingAtValue declaration as described here.

So for your second page, something like this:

.queryEnding(atValue: searchtv.text!+"\u{f8ff}", childKey: self.lastKey).observe(.value ,with: { (snapshot) in ....

You may also want to check out our sample demonstrating full text search using Algolia and Functions; it may get you a lot more mileage for contextual searching.

☼, Kato


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/85c58661-1315-4854-87e1-02d7987fab82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages