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

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

问题描述

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

解决方案

在我的情况下,我能够部分实现SQL LIKE

  databaseReference.orderByChild('_ searchLastName')
.startAt(queryText)
.endAt queryText +\\\)
.once(value)

在查询中使用的code> \ uf8ff 是Unicode范围中非常高的代码点(这是一个私有使用区域[PUA]代码)。因为它是Unicode中最常用的字符之后,查询匹配以 queryText 开头的所有值。


这样,通过 Fre我可以从数据库中得到Fred,Freddy,Frey作为 _searchLastName 属性中值的记录。


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?

解决方案

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

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

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天全站免登陆