如何在 Firebase 数据库中的字符串中进行简单搜索? [英] How to do a simple search in string in Firebase database?

查看:22
本文介绍了如何在 Firebase 数据库中的字符串中进行简单搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中创建一个简单的搜索,但在互联网上找不到任何关于它的内容,这比 2014 年更新.必须有更好的方法.有 startAt 和 endAt 函数,但它们不能按预期工作并且区分大小写.大家是怎么解决这个问题的?2016年怎么还没有这个功能?

I want to create a simple search in my app, but cannot find anything on interwebs about it, that's more recent than 2014. There must be a better way. There are startAt and endAt functions but they don't work as expected and are case sensitive. How do you guys solve this problem? How can this functionality still not exist in 2016?

推荐答案

就我而言,我能够通过以下方式部分实现 SQL LIKE:

In my case I was able to partly achieve a SQL LIKE in the following way:

databaseReference.orderByChild('_searchLastName')
                 .startAt(queryText)
                 .endAt(queryText+"uf8ff")

查询中使用的字符 uf8ff 在 Unicode 范围内是一个非常高的代码点(它是一个私有使用区 [PUA] 代码).因为它在 Unicode 中大多数常规字符之后,所以查询匹配所有以 queryText 开头的值.

这样,通过Fre"搜索,我可以从数据库中获取具有Fred, Freddy, Frey"作为 _searchLastName 属性值的记录.

The character uf8ff used in the query is a very high code point in the Unicode range (it is a Private Usage Area [PUA] code). Because it is after most regular characters in Unicode, the query matches all values that start with queryText.

In this way, searching by "Fre" I could get the records having "Fred, Freddy, Frey" as value in _searchLastName property from the database.

这篇关于如何在 Firebase 数据库中的字符串中进行简单搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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