使用部分字符串匹配进行Firebase查询 [英] Firebase querying with partial string match
问题描述
假设我有一个简单的firebase实时数据库结构,其中的键为username
,值为userid
.现在,我要按username
搜索userid
.如果用户名匹配,这是非常容易的.但是如何获得部分匹配的答案.更明确的是,如果我要使用SQL编写此代码,将类似于:
Suppose I have a simple firebase realtime database structure where the key is username
and the value is userid
. Now I want to search userid
by username
. It is quite easy if the username matches. but how to get the answer for partial match. To be more clear if i were to write this using SQL it would be something like:
SELECT userid
FROM tablename
WHERE username LIKE 'abc%'
SELECT userid
FROM tablename
WHERE username LIKE 'abc%'
它将为我提供所有userid
,其中username
以abc
开头.
如何编写此类针对Firebase的查询?了解我在android设备上使用它,并且可能有很多用户.
it will give me all the userid
where the username
starts with abc
.
How to write this type of query for firebase? Understand i am using this on a android device and there can be a lot of user.
推荐答案
根据Java Admin的文档,您可以执行类似的操作,它也应与Android一起使用
According to the doc of Java Admin you can do something like this it should also work with Android
对于以abc
开头的数据,
yourRef.orderByKey().startAt("abc").endAt("abc\uf8ff")
\ uf8ff在Unicode中大多数常规字符之后,因此查询应匹配以abc
开头的所有值.
The \uf8ff is after most regular characters in Unicode, so the query should matches all values that start with a abc
.
这篇关于使用部分字符串匹配进行Firebase查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!