The expectation of a search function in the Firebase database is to generate similar quantities of searching entities. But it does not precisely generate the input match. Implementing it generates a number of concerns when done manually. A simple function of “like” provides a close approximation of the desired result. It actually compares lower and upper-case variations of the input. The absence of such a function makes it difficult to select similar objects.
The limitations in the software cause problems where an attribute of the select query has multiple uses of “where,” creating an AND operation instead of an OR. Additionally, the fetch operation in Firebase is case-sensitive, as expected. Where provides a number of attributes like greaterthan(), lessthan(). Handling such functions to identify objects within a case-sensitive fetch proves to be difficult.
There are many ways we can fetch the necessary details. One such way is to create multiple fetch functions that search for all possible variations of the input. Another way is to use greaterthan() and lessthan() functions effectively to generate the desired result. Both these methods have a drawback, first one uses a multiple fetch function which causes a time delay. The second one uses a one-to-many function which has a high likelihood to cause failure.
{….
.where('db.Name',isGreaterThanOrEqualTo: inputName),
.where('db.Name',isGreaterThanOrEqualTo: inputName.toUpperCase()),
…}
The expectation of this code is to create an OR which looks to fetch both lowercase and uppercase of the input. But in reality, the check happens for a db.name which is both lower and uppercase at the same time which returns null.
The ideal way is to create a one-to-one function where a single pass and single comparison will generate the desired result. To achieve this we can use an additional field at the Firebase datatable which stores the name in only lowercase. While sending convert the needed input to lowercase this ensures that the comparison is done in a single pass.
{....
.where('db.searchName',isGreaterThanOrEqualTo: inputName.toLowerCase()),
….}
Here the search happens between a lowercase input and lowercase db.searchName.
This method is quite similar to map-reduce used in data science. We reduce the input and stored the name in lowercase to eliminate the complex comparison. Which is usually done by black box coding where the user involvement is minimum to none. Firebase search is case sensitive which is its inherent property. But we can make it appears to be case-insensitive with such a style.