0

This is my Firestore query in Dart:

getResults(){
    FirebaseFirestore.instance.collection('items').where("itemModel", isGreaterThanOrEqualTo: _searchQueryController.text.trim())
        .where("status", isEqualTo: "approved")
        .get()
        .then((results){
          setState(() {
            items = results;
          });
    });
  }

But it is case-sensitive. For example, if I have an itemModel called "Checkboard", it won't show up if I search for "checkboard"(with a lower-case 'c'). How can I make it case insensitive without modifying the data stored in my Firestore database? Here's a picture of my Firestore Database for reference: Picture of Firestore Database

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • 1
    Every time you searching something you have make your text also case sensitive by using `.toLowerCase()` ex: `_searchQueryController.text.toLowerCase().trim()` – Hemanth S Oct 29 '21 at 07:03

1 Answers1

3

All queries in Firestore are case-sensitive.

If you need a case-insensitive mechanism you'll need to write a separate field that contains the case-insensitive version of the field and query against it. For instance:

db.collection("items").where("itemModel", "==", "Checkboard")
db.collection("items").where("lowercaseItemModel", "==", "checkboard")

There is a great answer from @DanMcGrath that I recommend you read:

Or an alternative from @samthecodingman:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193