Press ESC to close

Android Firebase – Search/Filter with Search Highlighting

How to Search/Filter Firebase data.

In this tutorial, you will learn how to perform a search filter against firebase at the Firebase side rather than at the client side. The search will be performed using Firebase standard Query class. This much more efficient as the search is performed at the cloud side rather than in the users device.

Once the search hit occurs, we will highlight the keywords to show the user exactly why the result is among the filtered items.

Why Search Data?

Searching data is one of the fundamental operations that any database be it local or cloud-based has to perform. If you are having hundreds, thousands or even just a few dozens of data, you will need to search filter instead of scrolling through all the items. This saves you the item is also less mentally taxing. Thus being able to apply a search filter mechanism in your app makes your app user friendly to your users.

Video Tutorial

We have a detailed step by step YouTube tutorial for a search example. Please watch it and subscribe to our YouTube channel.

Step 1 : Create Project

In your android studio, go to New Project, Choose Empty Activity as your template, type your app name and Click finish to generate us a project skeleton.

Step 2 : Add Firebase to Project

The second step is to add Firebase to our project. Use the Firebase assistant from the tools menu item. Click Firebase, then go to Realtime database, then save/retrieve. If you are not sure then watch the video.

Step 3 : Add Dependencies

In your project you have two gradle scripsts:

(a). build.gradle(Project)

The first is the project level build.gradle. Take note we have added the google services:

You can see it’s just Plain Old Java Object class. Just don’t forget to provide an empty default constructor. We’ve also made it serializable to be make it transferable across activities. The key property will be excluded when saving/inserting Firebase data since it is autogenerated by Firebase.

Our two most important methods above are the search adn select. The select method allows us select all data from our Firebase Realtime database. The search method allows us search and filter our Firebase realtime database.

Resources

Share Article:

Tags:

When I was a 2nd year Software Engineering student, I buillt a now defunct online tool called Camposha(from Campus Share) using my then favorite language C#(ASP.NET) to compete OLX in my country(Kenya). The idea was to target campus students in Kenya. I got a few hundred signups but competing OLX proved too daunting. I decided to focus on my studies, learning other languages like Java,Python,Kotlin etc while meanwhile publishing tutorials at my YouTube Channel ProgrammingWizards TV which led to this site(camposha.info). Say hello or post me a suggestion: oclemmi@gmail.com .
Follow me below;
Github
, and on my channel:
ProgrammingWizards TV