'Ecommerce search like query using Firebase Firestore

Below is the Category collection DB structure:

Here is my CATERGORY collection DB structure

and here is the PRODUCT collection DB structure:

Here is the PRODUCT collection DB structure

I want to create a search query like similar to AMAZOM were you can just type in "shoes" and get a list of saying men shoes, women shoes, sports shoes etc. or just type in the name of the product and fetch the product.

As per my knowledge of Firestore, I have written a search query were it fetches all the data similar to the inputed letter. For example let's say I type in "S it retrieves the list of product starting with "S", below image is the result of it:

search result img

But that is not what I wanted and I have little knowledge of how to construct that kind search query that I want. How can I get my result using Firestore? I can twitch the current DB structure if I can achieve what I want but I don't want to destroy the whole structure too.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source