0

I need to search and filter from the Firestore collection. A sample collection with the name "products" is given below.

[
  {
    "id": 1,
    "name": "product 1",
    "description": "product description 1",
    "categoryId": 35,
    "categoryName": "Category 123",
    .......
  },
    {
    "id": 2,
    "name": "product 2",
    "description": "product description 2",
    "categoryId": 44,
    "categoryName": "Category 72",
    .......
  }
]

For example, if I entered a search text, I need a result from the Firestore collection where any of the fields contains a full or partial portion of the search text. Also, each product contains manufacturing and expiry dates. So I need to filter between a date range.

KIRAN K J
  • 632
  • 5
  • 28
  • 57

1 Answers1

1

Partial text search is not a supported feature with Firestore, it uses a direct comparison for values.

You will have to implement a custom search feature yourself by 3rd party API like Algolia with cloud functions or create a breakdown of all the text in strings that support broken down letter combinations - but this can increase reads unwantedly and I do not recommend it.

DIGI Byte
  • 4,225
  • 1
  • 12
  • 20
  • I think it is better to switch to AWS and do whatever we want. Because of the lack of join I have to perform some additional tasks with cloud functions. Now for this simple filtering, I have to again depend on another service. In this case, it is a third party. – KIRAN K J Sep 06 '21 at 04:20
  • that is entirely up to you, text search is a multi-faceted concept and can be divided into multiple solutions. And using multiple solutions is not out of the ordinary in any project. Firebase is a Restful SAAS and as such does not have any CPU or server overhead to do complex algorithmic sorting. it's why it has a free tier. – DIGI Byte Sep 06 '21 at 08:49
  • Will there be any extra read happen if I install Algolia. Also, will there be any delay – KIRAN K J Sep 07 '21 at 09:37
  • 1
    Algolia is its own solution that returns document ID's for you to fetch, this introduces a delay but it is quite fast and is not noticeable to most users. the reads itself are done through algolia, not firebase – DIGI Byte Sep 08 '21 at 01:17