简体   繁体   English

如何对来自 Flutter Firestore 的数据进行 toLowerCase()?

[英]How to toLowerCase() on data from Flutter Firestore?

I made an application and coded a search system between documents in the application.我做了一个应用程序并在应用程序中的文档之间编写了一个搜索系统。 But there is a problem:但有个问题:

在此处输入图像描述

在此处输入图像描述

The incoming record is registered as " Durmuş Bolat " in Firestore.传入记录在 Firestore 中注册为“ Durmuş Bolat ”。 And as you can see, the letter D of Durmuş is capitalized.如您所见,Durmuş 的字母D大写。 That's why I have to capitalize the first letter in the search.这就是为什么我必须将搜索中的第一个字母大写。 And that's a problem.这是一个问题。

I want to get the result of "Durmuş Bolat" even if I write it in the following ways:即使我用以下方式编写它,我也想得到“Durmuş Bolat”的结果:

  • durmuş bolat杜尔穆什博拉特
  • DURMUŞ BOLAT杜尔穆斯·博拉特
  • DuRmUs BoLaT杜鲁斯·博拉特

As a solution to this, I thought of shrinking the searched content and all the incoming content.作为对此的解决方案,我想到了缩小搜索内容和所有传入内容。 So all incoming data and searched content will be downsized with toLowerCase .因此,所有传入数据和搜索内容都将使用toLowerCase缩小。

I don't have the slightest idea where to place this toLowerCase code.我一点也不知道将这个 toLowerCase 代码放在哪里。 Can you help me?你能帮助我吗?

Codes:代码:

var _searchText;

return Scaffold(
  appBar: AppBar(
    title: Container(
      height: 50,
      width: 250,
      child: TextFormField(
        autofocus: true,
        style: TextStyle(color: Colors.white),
        onChanged: (value) {
          setState(() {
            _searchText = value;
          });
        },
      ),
    ),
  ),
  body: Column(
    children: [
      Container(
        height: MediaQuery.of(context).size.height * 0.8, //MediaQuery.of(context).size.height * 0.8,
        child: StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
          stream: FirebaseFirestore.instance.collection('bolatTamir').where('nameSurname', isGreaterThanOrEqualTo: _searchText).snapshots(),
          builder: (context, snapshot) {
            if (!snapshot.hasData) {
              return Center(
                child: CircularProgressIndicator(),
              );
            }
            return ListView.builder(
              itemCount: snapshot.data!.docs.length,
              itemBuilder: (context, index) {
                return InkWell(
                  child: ListTile(
                    leading: CircleAvatar(
                      backgroundImage: NetworkImage(snapshot.data!.docs[index].data()['urunFotografi']),
                    ),
                    title: Text(snapshot.data!.docs[index].data()['nameSurname'], style: TextStyle(fontSize: 20),),
                    subtitle: Text(snapshot.data!.docs[index].data()['yapildiMi'] == false ? 'Tamamlanmadı' : 'Tamamlandı', style: TextStyle(fontSize: 17),),
                    trailing: Text(snapshot.data!.docs[index].data()['tamirUcreti'], style: TextStyle(fontSize: 20),),
                  ),
                );
              },
            );
          },
        ),
      ),
    ],
  ),
);

Thank you in advance for your help.预先感谢您的帮助。

To my knowledge, lower-casing text that is already stored is not possible with Firebase.据我所知,Firebase 无法使用已存储的小写文本。 One can only lower-case the search term.只能将搜索词小写。

If it is just names and not tons of text, one could如果只是名称而不是大量文本,则可以

  • .split(' ') these names, then .split(' ')这些名字,然后
  • .toLowerCase() all resulting words, then .toLowerCase()所有结果词,然后
  • store them in a search-index-collection.将它们存储在搜索索引集合中。

Then, search this search-index-collection and resolve the $userId .然后,搜索这个 search-index-collection 并解析$userId . .

users/34td24y3gtdb724/
{
   name: 'Durmuş Bolat'
}

searchindex/
{
  word: 'durmuş',
  userId: 34td24y3gtdb724

  word: 'bolat',
  userId: 34td24y3gtdb724
}


Google itself asks to use Third-Party-Providers for full text search: Google 本身要求使用第三方提供商进行全文搜索:

https://cloud.google.com/firestore/docs/solutions/search https://cloud.google.com/firestore/docs/solutions/search

Also, there is an approach to generate permutations as an Array:此外,还有一种将排列生成为数组的方法:

https://medium.com/flobiz-blog/full-text-search-with-firestore-on-android-622af6ca5410 https://medium.com/flobiz-blog/full-text-search-with-firestore-on-android-622af6ca5410

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM