使 Firebase 查询搜索不区分大小写 [英] Making a firebase query search NOT case sensitive

查看:25
本文介绍了使 Firebase 查询搜索不区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Firebase 数据库中提取信息,但它是一个区分大小写的查询,我不希望它区分大小写,有没有办法在 Android Studio 中使查询不区分大小写,这里是查询代码

I wanna pull information from a Firebase Database but it's a case sensitive query, and i don't want it to be case sensitive, is there a way to make the query NOT case sensitive in Android Studio ,Here is the query code

DatabaseReference SearchRef = (DatabaseReference) FirebaseDatabase.getInstance().getReference().child("Child1").orderByChild("Child2").startAt(searchText).endAt(searchText + "uf8ff"); // uf8ff is a white space
    Query Searchquery = Searchref;
    Searchquery.addValueEventListener...

推荐答案

当使用 Firebase Database 时,这就是你从 orderByChild() 函数中获得的.它以升序或降序返回数据,您无法使用扩展查询自定义结果.

When using Firebase Database, that is the much you get to from orderByChild() function. It returns data either ascending or descending order and you cannot customize your result with extended queries.

但是,您可以尝试其他可能更贵的东西.将您想要的所有孩子作为数组获取,保存 Child2 及其键.然后,您可以将字符串更改为大写或小写,并使用键访问所需的结果.

However, You can try a something else that may be a bit more expensive. Get all the children you want as an array, saving Child2 and its key. You can then change the string to upper case or lower case and access the desired result using the key.

参考结果为

FirebaseDatabase.getInstance().getReference("Child1").child(key);

编辑

添加您的逻辑,如果您希望戴夫"或戴夫"返回戴夫和戴夫您可以将查询编辑为 startAt(text.toUppercase)endAt(text.toLowerCase+ "uf8ff").这将返回 DAVE、Dave、dave 等

To add on your logic, If you want "Dave" or "dave" to return Dave and dave You can edit your query to startAt(text.toUppercase) and endAt(text.toLowerCase+ "uf8ff"). This will return DAVE, Dave, dave etc

这篇关于使 Firebase 查询搜索不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆