0

I looked in many places, but I couldn't find a correct and precise solution, so I'm asking again. I have an application and this application has a search query that works like this under normal conditions.

ds = await _firestore
        .collectionGroup("Cars")
        .where("name", isEqualTo: widget.name).get();

In this usage, I can get car names that match exactly what I type of widget.name.

But I want to run a query like this. For example, there are car names in this style in my database: Mercedes Sport, Bmw Sport, Audi Sport, Porsche. When I type Sport in the search field, I want to get Mercedes Sport, Bmw Sport and Audi Sport data. Or when I type orsch I want to get Porsche data or when I type Mer I want to get Mercedes Sport data. In other words, I want to display the string data containing the string that I entered briefly in the search section and searched.

I need a proper solution that will correctly meet all of the requirements I have described.

Rkdio
  • 153
  • 2
  • 13
  • Firestore does not offer substring queries as you require. You will need another database for this. Firestore can do prefix queries, though, as described in the first duplicate. But its indexes aren't able to search for arbitrary substrings. – Doug Stevenson Sep 06 '22 at 23:09
  • I know firestore can't do a lot of things directly but I thought maybe there was a way – Rkdio Sep 06 '22 at 23:12
  • There is no way. – Doug Stevenson Sep 06 '22 at 23:12
  • and there has to be a way because a lot of people are using firebase and many end users can't type everything correctly while searching. if there is no solution, there is nothing to do, anyway, thank you for your answer, how do you suggest me to do something? – Rkdio Sep 06 '22 at 23:13
  • As I mentioned, you can use a different database, perhaps at the same time as Firestore. A discussion on how to do this is too big for Stack Overflow. I suggest posting to a discussion forum if you want to engage others with ideas. – Doug Stevenson Sep 06 '22 at 23:15
  • all my code and my application is completely dependent on firestore so there is no way to use a new database. I think there are some 3rd party software that can be added as firestore plugin, can you recommend me to use them? – Rkdio Sep 06 '22 at 23:17
  • I suggest posting to a discussion forum to get ideas about alternatives. Stack Overflow is not a discussion forum that accepts recommendations for software products. – Doug Stevenson Sep 06 '22 at 23:18
  • This is the documented solution on how to add full text search to Firestore: https://firebase.google.com/docs/firestore/solutions/search. As Doug said, it uses another database for the full-text search part. There are also some extensions that make this even easier. Search for "Search" in https://firebase.google.com/products/extensions for more – Frank van Puffelen Sep 07 '22 at 00:12
  • Since I have never used an extension of this style before, I hesitated to use it, but if it is not difficult to use, I will try. – Rkdio Sep 07 '22 at 10:19

0 Answers0