1
  1. I am trying with this code to search the product by name in the database but it gives those data which is the same as in a database. so give a better solution.

Code:

 let response =  await db
            .collection("products")
            .where("productName", ">=", req.body.searchText)
            .where("productName", "<=", req.body.searchText + '\uf8ff')
            .get();
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193

1 Answers1

0

Cloud Firestore doesn't provide a solution for full-text search. As you can see, you can use Elastic Search, Algolia or Typesense.

If you don't want such functionality, you can still use Firestore with a search that looks like this:

db.collection("products").orderBy("name")
    .startAt(req.body.searchText)
    .endAt(req.body.searchText + "\uf8ff");

If you're interested, for a better understanding, I recommend you read the following article:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Thanks for answering it's working but similar to earlier, but I want result incase sensetive let's suppose I search "pen" It should return result for "Pen" and "pen" As well but currently it match exact string – Akshay Udapure Sep 30 '22 at 16:18
  • Queries in Firesroe are case-sensitive. To achieve what you want, check [this answer](https://stackoverflow.com/questions/50005587/firestore-database-query-ignore-case-case-insenstive-and-like-clause) and [this answer](https://stackoverflow.com/questions/46554793/are-cloud-firestore-queries-still-case-sensitive). – Alex Mamo Sep 30 '22 at 16:21
  • Hey Akshay. Can I help you with other information? – Alex Mamo Oct 01 '22 at 09:04
  • 1
    I will try this but I don't think It will fulfill my requirement. I will let you know. – Akshay Udapure Oct 01 '22 at 10:40
  • Ok, give it a try and tell me if it works. – Alex Mamo Oct 01 '22 at 10:41