Firebase RTDB Search for a keyword in a list of keywords

Viewed 152

I am using Firebase RTDB to access my data using the Flutter app. The data has the following attributes:

{
  'Category': 'Food',
  'Product Description': 'Energy Drink',
  'Product Picture': 'image_link',
  'Product Title': 'Coca Cola',
  'Price': 40000,
  'inStock': 1,
  'keywords':[
    'coco cola',
    'energy drink',
    'drink',
    'other keywords'
  ]
}

I would like to use the keywords field to search for a specific product. How can I do that?

I know about 'orderby' and 'equalto' keywords in Firebase RTDB but how to use it with a list?

Or how do I change the structure of the data so that I can efficiently search for specific keywords?

1 Answers

Store the keywords as maps. So it would be like keywords: {'coca cola':true, ...}

Then you can do

.orderBy('keywords/coca cola').equalTo(true)
Related